From dc9c62a45f0033068cf10ded0d922f785e35cd52 Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Fri, 29 Oct 2021 17:21:24 -0700 Subject: [PATCH] Removed primaryVariant from usage by the SnackBar. (#92443) --- .../flutter/lib/src/material/snack_bar.dart | 4 +- .../flutter/test/material/snack_bar_test.dart | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 8b860e766b4..a37085330b5 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -421,7 +421,7 @@ class _SnackBarState extends State { final ColorScheme colorScheme = theme.colorScheme; final SnackBarThemeData snackBarTheme = theme.snackBarTheme; final bool isThemeDark = theme.brightness == Brightness.dark; - final Color buttonColor = isThemeDark ? colorScheme.primaryVariant : colorScheme.secondary; + final Color buttonColor = isThemeDark ? colorScheme.primary : colorScheme.secondary; // SnackBar uses a theme that is the opposite brightness from // the surrounding theme. @@ -433,8 +433,6 @@ class _SnackBarState extends State { colorScheme: ColorScheme( primary: colorScheme.onPrimary, primaryVariant: colorScheme.onPrimary, - // For the button color, the spec says it should be primaryVariant, but for - // backward compatibility on light themes we are leaving it as secondary. secondary: buttonColor, secondaryVariant: colorScheme.onSecondary, surface: colorScheme.onSurface, diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart index 330511f29c4..a4477ecec91 100644 --- a/packages/flutter/test/material/snack_bar_test.dart +++ b/packages/flutter/test/material/snack_bar_test.dart @@ -667,6 +667,45 @@ void main() { expect(renderModel.color, equals(darkTheme.colorScheme.onSurface)); }); + testWidgets('Dark theme SnackBar has primary text buttons', (WidgetTester tester) async { + final ThemeData darkTheme = ThemeData.dark(); + await tester.pumpWidget( + MaterialApp( + theme: darkTheme, + home: Scaffold( + body: Builder( + builder: (BuildContext context) { + return GestureDetector( + onTap: () { + Scaffold.of(context).showSnackBar( + SnackBar( + content: const Text('I am a snack bar.'), + duration: const Duration(seconds: 2), + action: SnackBarAction( + label: 'ACTION', + onPressed: () { }, + ), + ), + ); + }, + child: const Text('X'), + ); + }, + ), + ), + ), + ); + + await tester.tap(find.text('X')); + await tester.pump(); // start animation + await tester.pump(const Duration(milliseconds: 750)); + + final TextStyle buttonTextStyle = tester.widget( + find.descendant(of: find.text('ACTION'), matching: find.byType(RichText)) + ).text.style!; + expect(buttonTextStyle.color, equals(darkTheme.colorScheme.primary)); + }); + testWidgets('SnackBar should inherit theme data from its ancestor.', (WidgetTester tester) async { final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors( primaryColor: Colors.black,