From dfa489c3940b7afc7ce86927aa5963f93d2e8731 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 5 Feb 2019 14:36:43 -0800 Subject: [PATCH] Update OutlineButton on-pressed fill color (#27519) --- .../lib/src/material/outline_button.dart | 5 +- .../test/material/outline_button_test.dart | 61 ++++++++++++++++++- .../test/material/theme_defaults_test.dart | 2 +- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/material/outline_button.dart b/packages/flutter/lib/src/material/outline_button.dart index 774bcc7c9d..4a0b6c1f0e 100644 --- a/packages/flutter/lib/src/material/outline_button.dart +++ b/packages/flutter/lib/src/material/outline_button.dart @@ -343,10 +343,7 @@ class _OutlineButtonState extends State<_OutlineButton> with SingleTickerProvide } Color _getFillColor() { - final bool themeIsDark = widget.brightness == Brightness.dark; - final Color color = widget.color ?? (themeIsDark - ? const Color(0x00000000) - : const Color(0x00FFFFFF)); + final Color color = widget.color ?? Theme.of(context).canvasColor; final Tween colorTween = ColorTween( begin: color.withAlpha(0x00), end: color.withAlpha(0xFF), diff --git a/packages/flutter/test/material/outline_button_test.dart b/packages/flutter/test/material/outline_button_test.dart index 01a37cd982..e977919217 100644 --- a/packages/flutter/test/material/outline_button_test.dart +++ b/packages/flutter/test/material/outline_button_test.dart @@ -121,7 +121,7 @@ void main() { // Wait for the border color to change from disabled to enabled. await tester.pumpAndSettle(); - // Expect that the button is disabled and painted with the enabled border color. + // Expect that the button is enabled and painted with the enabled border color. expect(tester.widget(outlineButton).enabled, true); expect( outlineButton, @@ -314,4 +314,63 @@ void main() { 'splashColor: Color(0xff9e9e9e)', ]); }); + + testWidgets('OutlineButton pressed fillColor default', (WidgetTester tester) async { + Widget buildFrame(ThemeData theme) { + return MaterialApp( + theme: theme, + home: Scaffold( + body: Center( + child: OutlineButton( + onPressed: () {}, + child: const Text('Hello'), + ), + ), + ), + ); + } + + await tester.pumpWidget(buildFrame(ThemeData.dark())); + final Finder button = find.byType(OutlineButton); + final Offset center = tester.getCenter(button); + + // Default value for dark Theme.of(context).canvasColor as well as + // the OutlineButton fill color when the button has been pressed. + Color fillColor = Colors.grey[850]; + + // Initially the interior of the button is transparent. + expect(button, paints..path(color: fillColor.withAlpha(0x00))); + + // Tap-press gesture on the button triggers the fill animation. + TestGesture gesture = await tester.startGesture(center); + await tester.pump(); // Start the button fill animation. + await tester.pump(const Duration(milliseconds: 200)); // Animation is complete. + expect(button, paints..path(color: fillColor.withAlpha(0xFF))); + + // Tap gesture completes, button returns to its initial configuration. + await gesture.up(); + await tester.pumpAndSettle(); + expect(button, paints..path(color: fillColor.withAlpha(0x00))); + + await tester.pumpWidget(buildFrame(ThemeData.light())); + await tester.pumpAndSettle(); // Finish the theme change animation. + + // Default value for light Theme.of(context).canvasColor as well as + // the OutlineButton fill color when the button has been pressed. + fillColor = Colors.grey[50]; + + // Initially the interior of the button is transparent. + expect(button, paints..path(color: fillColor.withAlpha(0x00))); + + // Tap-press gesture on the button triggers the fill animation. + gesture = await tester.startGesture(center); + await tester.pump(); // Start the button fill animation. + await tester.pump(const Duration(milliseconds: 200)); // Animation is complete. + expect(button, paints..path(color: fillColor.withAlpha(0xFF))); + + // Tap gesture completes, button returns to its initial configuration. + await gesture.up(); + await tester.pumpAndSettle(); + expect(button, paints..path(color: fillColor.withAlpha(0x00))); + }); } diff --git a/packages/flutter/test/material/theme_defaults_test.dart b/packages/flutter/test/material/theme_defaults_test.dart index 9ae205d4e3..32a7610ec5 100644 --- a/packages/flutter/test/material/theme_defaults_test.dart +++ b/packages/flutter/test/material/theme_defaults_test.dart @@ -143,7 +143,7 @@ void main() { final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); expect(raw.textStyle.color, const Color(0xdd000000)); - expect(raw.fillColor, const Color(0x00ffffff)); + expect(raw.fillColor, const Color(0x00fafafa)); expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc) expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8) expect(raw.elevation, 0.0);