Unverified Commit 34a62848 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Fixed the default color of the trailing widget on app bar (#110635)

parent 7e7c1e4a
...@@ -942,11 +942,13 @@ class _AppBarState extends State<AppBar> { ...@@ -942,11 +942,13 @@ class _AppBarState extends State<AppBar> {
?? appBarTheme.iconTheme ?? appBarTheme.iconTheme
?? defaults.iconTheme!.copyWith(color: foregroundColor); ?? defaults.iconTheme!.copyWith(color: foregroundColor);
final Color? actionForegroundColor = widget.foregroundColor
?? appBarTheme.foregroundColor;
IconThemeData actionsIconTheme = widget.actionsIconTheme IconThemeData actionsIconTheme = widget.actionsIconTheme
?? appBarTheme.actionsIconTheme ?? appBarTheme.actionsIconTheme
?? widget.iconTheme ?? widget.iconTheme
?? appBarTheme.iconTheme ?? appBarTheme.iconTheme
?? defaults.actionsIconTheme?.copyWith(color: foregroundColor) ?? defaults.actionsIconTheme?.copyWith(color: actionForegroundColor)
?? overallIconTheme; ?? overallIconTheme;
TextStyle? toolbarTextStyle = backwardsCompatibility TextStyle? toolbarTextStyle = backwardsCompatibility
......
...@@ -2876,6 +2876,42 @@ void main() { ...@@ -2876,6 +2876,42 @@ void main() {
expect(actionIconColor(), foregroundColor); 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 <Widget>[
Icon(Icons.ac_unit)
],
),
),
),
);
Color textColor() {
return tester.renderObject<RenderParagraph>(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 // Regression test for https://github.com/flutter/flutter/issues/107305
group('Icons are colored correctly by IconTheme and ActionIconTheme in M3', () { group('Icons are colored correctly by IconTheme and ActionIconTheme in M3', () {
testWidgets('Icons and IconButtons are colored by IconTheme in M3', (WidgetTester tester) async { testWidgets('Icons and IconButtons are colored by IconTheme in M3', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment