From 890e6ccea69953e780213cc84a4c87c7126172b4 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Fri, 25 Sep 2020 07:31:56 -0700 Subject: [PATCH] Replaced obsolete use of FlatButton with TextButton (#66597) --- .../lib/src/material/text_selection.dart | 25 +++++++++++-------- .../test/material/text_field_test.dart | 10 ++++---- .../test/widgets/selectable_text_test.dart | 10 ++++---- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/src/material/text_selection.dart b/packages/flutter/lib/src/material/text_selection.dart index bb9028d13c..d8904b70b4 100644 --- a/packages/flutter/lib/src/material/text_selection.dart +++ b/packages/flutter/lib/src/material/text_selection.dart @@ -11,15 +11,14 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'button_theme.dart'; import 'colors.dart'; import 'constants.dart'; import 'debug.dart'; -import 'flat_button.dart'; import 'icon_button.dart'; import 'icons.dart'; import 'material.dart'; import 'material_localizations.dart'; +import 'text_button.dart'; import 'text_selection_theme.dart'; import 'theme.dart'; @@ -84,22 +83,26 @@ class _TextSelectionToolbarState extends State<_TextSelectionToolbar> with Ticke Widget _getItem(_ItemData itemData, bool isFirst, bool isLast) { assert(isFirst != null); assert(isLast != null); - return ButtonTheme.fromButtonThemeData( - data: ButtonTheme.of(context).copyWith( - height: kMinInteractiveDimension, - minWidth: kMinInteractiveDimension, - ), - child: FlatButton( - onPressed: itemData.onPressed, + + // TODO(hansmuller): Should be colorScheme.onSurface + final ThemeData theme = Theme.of(context); + final bool isDark = theme.colorScheme.brightness == Brightness.dark; + final Color primary = isDark ? Colors.white : Colors.black87; + + return TextButton( + style: TextButton.styleFrom( + primary: primary, + shape: const RoundedRectangleBorder(), + minimumSize: const Size(kMinInteractiveDimension, kMinInteractiveDimension), padding: EdgeInsets.only( // These values were eyeballed to match the native text selection menu // on a Pixel 2 running Android 10. left: 9.5 + (isFirst ? 5.0 : 0.0), right: 9.5 + (isLast ? 5.0 : 0.0), ), - shape: Border.all(width: 0.0, color: Colors.transparent), - child: Text(itemData.label), ), + onPressed: itemData.onPressed, + child: Text(itemData.label), ); } diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 69527d0f4d..7af6f5c702 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -6172,7 +6172,7 @@ void main() { ); // But don't trigger the toolbar. - expect(find.byType(FlatButton), findsNothing); + expect(find.byType(TextButton), findsNothing); }, variant: const TargetPlatformVariant({ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows })); testWidgets( @@ -6297,7 +6297,7 @@ void main() { ); // Selected text shows 4 toolbar buttons: cut, copy, paste, select all - expect(find.byType(FlatButton), findsNWidgets(4)); + expect(find.byType(TextButton), findsNWidgets(4)); }, variant: const TargetPlatformVariant({ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows })); testWidgets( @@ -6346,7 +6346,7 @@ void main() { ); // Selected text shows 4 toolbar buttons: cut, copy, paste, select all - expect(find.byType(FlatButton), findsNWidgets(4)); + expect(find.byType(TextButton), findsNWidgets(4)); }, variant: const TargetPlatformVariant({ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows })); testWidgets( @@ -6628,7 +6628,7 @@ void main() { ); // Collapsed toolbar shows 4 buttons: cut, copy, paste, select all - expect(find.byType(FlatButton), findsNWidgets(4)); + expect(find.byType(TextButton), findsNWidgets(4)); }, variant: const TargetPlatformVariant({ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows })); testWidgets( @@ -7006,7 +7006,7 @@ void main() { await gesture.up(); await tester.pump(); - expect(find.byType(FlatButton), findsNothing); + expect(find.byType(TextButton), findsNothing); }, variant: const TargetPlatformVariant({ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows })); testWidgets('force press selects word', (WidgetTester tester) async { diff --git a/packages/flutter/test/widgets/selectable_text_test.dart b/packages/flutter/test/widgets/selectable_text_test.dart index 3d14af0e64..4ab69d88d4 100644 --- a/packages/flutter/test/widgets/selectable_text_test.dart +++ b/packages/flutter/test/widgets/selectable_text_test.dart @@ -2442,7 +2442,7 @@ void main() { ); // But don't trigger the toolbar. - expect(find.byType(FlatButton), findsNothing); + expect(find.byType(TextButton), findsNothing); }, ); @@ -2564,7 +2564,7 @@ void main() { ); // Selected text shows 2 toolbar buttons: copy, select all - expect(find.byType(FlatButton), findsNWidgets(2)); + expect(find.byType(TextButton), findsNWidgets(2)); }, ); @@ -2613,7 +2613,7 @@ void main() { ); // Selected text shows 2 toolbar buttons: copy, select all - expect(find.byType(FlatButton), findsNWidgets(2)); + expect(find.byType(TextButton), findsNWidgets(2)); }, ); @@ -2769,7 +2769,7 @@ void main() { ); // Collapsed toolbar shows 2 buttons: copy, select all - expect(find.byType(FlatButton), findsNWidgets(2)); + expect(find.byType(TextButton), findsNWidgets(2)); }, ); @@ -3175,7 +3175,7 @@ void main() { await gesture.up(); await tester.pump(); - expect(find.byType(FlatButton), findsNothing); + expect(find.byType(TextButton), findsNothing); }); testWidgets('force press selects word', (WidgetTester tester) async {