From 34a628483c3874c43b7bb3676a4ec0258e58b7f0 Mon Sep 17 00:00:00 2001 From: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Date: Wed, 31 Aug 2022 10:15:48 -0700 Subject: [PATCH] Fixed the default color of the trailing widget on app bar (#110635) --- .../flutter/lib/src/material/app_bar.dart | 4 ++- .../flutter/test/material/app_bar_test.dart | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 31facb43cf..b4e69b8f3a 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -942,11 +942,13 @@ class _AppBarState extends State { ?? appBarTheme.iconTheme ?? defaults.iconTheme!.copyWith(color: foregroundColor); + final Color? actionForegroundColor = widget.foregroundColor + ?? appBarTheme.foregroundColor; IconThemeData actionsIconTheme = widget.actionsIconTheme ?? appBarTheme.actionsIconTheme ?? widget.iconTheme ?? appBarTheme.iconTheme - ?? defaults.actionsIconTheme?.copyWith(color: foregroundColor) + ?? defaults.actionsIconTheme?.copyWith(color: actionForegroundColor) ?? overallIconTheme; TextStyle? toolbarTextStyle = backwardsCompatibility diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index acf54c2ead..783758b714 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -2876,6 +2876,42 @@ void main() { expect(actionIconColor(), foregroundColor); }); + testWidgets('Leading, title, and actions show correct default colors', (WidgetTester tester) async { + final ThemeData themeData = ThemeData.from( + colorScheme: const ColorScheme.light( + onPrimary: Colors.blue, + onSurface: Colors.red, + onSurfaceVariant: Colors.yellow), + ); + final bool material3 = themeData.useMaterial3; + await tester.pumpWidget( + MaterialApp( + theme: themeData, + home: Scaffold( + appBar: AppBar( + leading: const Icon(Icons.add_circle), + title: const Text('title'), + actions: const [ + Icon(Icons.ac_unit) + ], + ), + ), + ), + ); + + Color textColor() { + return tester.renderObject(find.text('title')).text.style!.color!; + } + Color? leadingIconColor() => iconStyle(tester, Icons.add_circle)?.color; + Color? actionIconColor() => iconStyle(tester, Icons.ac_unit)?.color; + + // M2 default color are onPrimary, and M3 has onSurface for leading and title, + // onSurfaceVariant for actions. + expect(textColor(), material3 ? Colors.red : Colors.blue); + expect(leadingIconColor(), material3 ? Colors.red : Colors.blue); + expect(actionIconColor(), material3 ? Colors.yellow : Colors.blue); + }); + // Regression test for https://github.com/flutter/flutter/issues/107305 group('Icons are colored correctly by IconTheme and ActionIconTheme in M3', () { testWidgets('Icons and IconButtons are colored by IconTheme in M3', (WidgetTester tester) async {