blob: 1b0ca204a41fead4bcb1ce69c99896d3147709cf [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'constants.dart';
import 'text_button.dart';
import 'theme.dart';
const TextStyle _kToolbarButtonFontStyle = TextStyle(
inherit: false,
fontSize: 14.0,
letterSpacing: -0.15,
fontWeight: FontWeight.w400,
const EdgeInsets _kToolbarButtonPadding = EdgeInsets.fromLTRB(
/// A [TextButton] for the Material desktop text selection toolbar.
class DesktopTextSelectionToolbarButton extends StatelessWidget {
/// Creates an instance of DesktopTextSelectionToolbarButton.
const DesktopTextSelectionToolbarButton({
required this.onPressed,
required this.child,
/// Create an instance of [DesktopTextSelectionToolbarButton] whose child is
/// a [Text] widget in the style of the Material text selection toolbar.
required BuildContext context,
required this.onPressed,
required String text,
}) : child = Text(
overflow: TextOverflow.ellipsis,
style: _kToolbarButtonFontStyle.copyWith(
color: Theme.of(context).colorScheme.brightness == Brightness.dark
? Colors.white
: Colors.black87,
/// {@macro flutter.material.TextSelectionToolbarTextButton.onPressed}
final VoidCallback onPressed;
/// {@macro flutter.material.TextSelectionToolbarTextButton.child}
final Widget child;
Widget build(BuildContext context) {
// TODO(hansmuller): Should be colorScheme.onSurface
final ThemeData theme = Theme.of(context);
final bool isDark = theme.colorScheme.brightness == Brightness.dark;
final Color foregroundColor = isDark ? Colors.white : Colors.black87;
return SizedBox(
width: double.infinity,
child: TextButton(
style: TextButton.styleFrom(
alignment: Alignment.centerLeft,
enabledMouseCursor: SystemMouseCursors.basic,
disabledMouseCursor: SystemMouseCursors.basic,
foregroundColor: foregroundColor,
shape: const RoundedRectangleBorder(),
minimumSize: const Size(kMinInteractiveDimension, 36.0),
padding: _kToolbarButtonPadding,
onPressed: onPressed,
child: child,