From 07d015d441bd8881f5dda37a5f03a1442d83988d Mon Sep 17 00:00:00 2001 From: xster Date: Thu, 7 Feb 2019 13:20:39 -0800 Subject: [PATCH] Let text selection toolbar buttons be independent from theme (#27573) --- .../lib/src/cupertino/text_selection.dart | 9 ++- .../test/cupertino/text_field_test.dart | 62 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/text_selection.dart b/packages/flutter/lib/src/cupertino/text_selection.dart index 68bc38977f..df4d46152e 100644 --- a/packages/flutter/lib/src/cupertino/text_selection.dart +++ b/packages/flutter/lib/src/cupertino/text_selection.dart @@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter/rendering.dart'; import 'button.dart'; +import 'colors.dart'; import 'localizations.dart'; // Padding around the line at the edge of the text selection that has 0 width and @@ -33,9 +34,11 @@ const EdgeInsets _kToolbarButtonPadding = EdgeInsets.symmetric(vertical: 10.0, h const BorderRadius _kToolbarBorderRadius = BorderRadius.all(Radius.circular(7.5)); const TextStyle _kToolbarButtonFontStyle = TextStyle( + inherit: false, fontSize: 14.0, letterSpacing: -0.11, fontWeight: FontWeight.w300, + color: CupertinoColors.white, ); /// Paints a triangle below the toolbar. @@ -113,8 +116,12 @@ class _TextSelectionToolbar extends StatelessWidget { ClipRRect( borderRadius: _kToolbarBorderRadius, child: DecoratedBox( - decoration: const BoxDecoration( + decoration: BoxDecoration( color: _kToolbarDividerColor, + borderRadius: _kToolbarBorderRadius, + // Add a hairline border with the button color to avoid + // antialiasing artifacts. + border: Border.all(color: _kToolbarBackgroundColor, width: 0), ), child: Row(mainAxisSize: MainAxisSize.min, children: items), ), diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 9df9a57a9c..e9c866dd5d 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -702,6 +702,68 @@ void main() { expect(controller.text, 'abcdef'); }); + testWidgets('toolbar has the same visual regardless of theming', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController( + text: "j'aime la poutine", + ); + + await tester.pumpWidget( + CupertinoApp( + home: Column( + children: [ + CupertinoTextField( + controller: controller, + ), + ], + ), + ), + ); + + await tester.longPressAt( + tester.getTopRight(find.text("j'aime la poutine")) + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 200)); + + Text text = tester.widget(find.text('Paste')); + expect(text.style.color, CupertinoColors.white); + expect(text.style.fontSize, 14); + expect(text.style.letterSpacing, -0.11); + expect(text.style.fontWeight, FontWeight.w300); + + // Change the theme. + await tester.pumpWidget( + CupertinoApp( + theme: const CupertinoThemeData( + brightness: Brightness.dark, + textTheme: CupertinoTextThemeData( + textStyle: TextStyle(fontSize: 100, fontWeight: FontWeight.w800), + ), + ), + home: Column( + children: [ + CupertinoTextField( + controller: controller, + ), + ], + ), + ), + ); + + await tester.longPressAt( + tester.getTopRight(find.text("j'aime la poutine")) + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 200)); + + text = tester.widget(find.text('Paste')); + // The toolbar buttons' text are still the same style. + expect(text.style.color, CupertinoColors.white); + expect(text.style.fontSize, 14); + expect(text.style.letterSpacing, -0.11); + expect(text.style.fontWeight, FontWeight.w300); + }); + testWidgets('copy paste', (WidgetTester tester) async { await tester.pumpWidget( CupertinoApp(