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

This commit is contained in:
Qun Cheng
2022-08-31 10:15:48 -07:00
committed by GitHub
parent 7e7c1e4a72
commit 34a628483c
2 changed files with 39 additions and 1 deletions

View File

@@ -942,11 +942,13 @@ class _AppBarState extends State<AppBar> {
?? 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

View File

@@ -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 <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
group('Icons are colored correctly by IconTheme and ActionIconTheme in M3', () {
testWidgets('Icons and IconButtons are colored by IconTheme in M3', (WidgetTester tester) async {