Repository navigation
[Material3] AppBar does not respect foregroundColor or iconTheme for leading and actions in some cases #130485
Copy link
Copy link
Closed
Labels
customer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Create a new empty
MaterialAppwithScaffoldandAppBar. - Set
foregroundColortoColors.black87in light theme, orColors.whitein dark theme. (Those are thekDefaultIconLightColorandkDefaultIconDarkColor). - Set
ThemeDatawithuseMaterial3: true. - Add some leading or actions to AppBar. For example:
leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
Expected results
When we set foregroundColor or iconTheme in AppBar to Colors.black87 in Light mode, or Colors.white in Dark mode, this color should be used for leading and action buttons.
Actual results
foregroundColor or iconTheme set in AppBar is ignored, and the default ColorScheme onSurfaceVariant color is used instead.
Code sample
Code sample
This is code for a simple app to test the issue:import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: const ColorScheme.dark().copyWith(onSurfaceVariant: Colors.red),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
foregroundColor: Colors.white, // This color is ignored and icons are red!
iconTheme: const IconThemeData(color: Colors.white), // This color is also ignored and icons are red!
leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
actions: <Widget>[
IconButton(icon: const Icon(Icons.add), onPressed: () {}),
],
),
),
);
}
}Test
This is slightly edited code from app_bar_test.dart. This test will fail with Colors.black87, but is successful with any other color.
testWidgets('The foregroundColor property of the AppBar overrides any IconButtonTheme present in the theme - M3', (WidgetTester tester) async {
final ThemeData themeData = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
theme: themeData,
home: Scaffold(
appBar: AppBar(
foregroundColor: Colors.black87,
leading: IconButton(icon: const Icon(Icons.menu), onPressed: () {}),
actions: <Widget>[
IconButton(icon: const Icon(Icons.add), onPressed: () {}),
],
),
),
),
);
Color? leadingIconButtonColor() => iconStyle(tester, Icons.menu)?.color;
Color? actionIconButtonColor() => iconStyle(tester, Icons.add)?.color;
expect(leadingIconButtonColor(), Colors.black87);
expect(actionIconButtonColor(), Colors.black87);
});Screenshots or Video
Screenshots / Video demonstration
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel master, 3.13.0-3.0.pre.21, on Linux Mint 21.1 5.19.0-46-generic, locale cs_CZ.UTF-8)
• Flutter version 3.13.0-3.0.pre.21 on channel master at /home/helu/Software/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 47ba59c762 (8 hours ago), 2023-07-12 20:46:57 -0400
• Engine revision 1b1ccdd1f5
• Dart version 3.1.0 (build 3.1.0-302.0.dev)
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/helu/Software/android-sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /home/helu/Software/android-sdk/
• Java binary at: /home/helu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 14.0.0-1ubuntu1
• cmake version 3.22.1
• ninja version 1.10.1
• pkg-config version 0.29.2
[✓] Android Studio (version 2022.2)
• Android Studio at /home/helu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[!] Android Studio (version unknown)
• Android Studio at /home/helu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to determine Android Studio version.
• android-studio-dir = /home/helu/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.80.0)
• VS Code at /usr/share/code
• Flutter extension version 3.68.0
[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator)
• Linux (desktop) • linux • linux-x64 • Linux Mint 21.1 5.19.0-46-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198
! Device R3CT30WFRLD is not authorized.
You might need to check your device for an authorization dialog.
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.```
</details>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
customer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.found in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.13Found to occur in 3.13Found to occur in 3.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages team
Type
Projects
- StatusShow more project fieldsDone (PR merged)
- StatusShow more project fields✅ Done



Activity
dam-ease commentedon Jul 13, 2023
Hi @HE-LU. Thanks for filing this issue. I'm able to reproduce this on the latest
masterandstablechannels.flutter doctor -v
[-]Material3 AppBar does not respect `foregroundColor` or `iconTheme` for leading and actions in some cases[/-][+][Material3] AppBar does not respect `foregroundColor` or `iconTheme` for leading and actions in some cases[/+]1 remaining item
TahaTesser commentedon Jul 13, 2023
For some reason fallback to

IconTheme.mergefails only withColors.white, other colors work fine.When printing color inside
IconThemeData.mergeColors.white(as you can see here last color is not white)Colors.green(as you can see here all other colors are same, green)HansMuller commentedon Jul 13, 2023
CC @QuncCccccc
QuncCccccc commentedon Jul 13, 2023
I think there are some problems when we compare the default color objects in icon_button.dart. The comparison only compares the value instead of objects.
(A little context why I added this code) When we have an IconButton and also provide a IconTheme, we want IconButton to respect IconTheme.color and IconTheme.size if they are not null. But IconTheme always has a fallback when we call
IconTheme.of(context), and will prevent IconButton to have its own defaults. So we added that check.Fix:
We should change the method to:
And also we need to update the declaration of
kDefaultIconLightColorandkDefaultIconDarkColortoUsing
constwill point to same object.TahaTesser commentedon Jul 14, 2023
Thanks, @QuncCccccc! I'll take a look into this and write tests for the PR.
Fix `iconTheme` in `AppBar` doesn't apply custom `Colors.white` in th…
Fix `iconTheme` in `AppBar` doesn't apply custom `Colors.white` in th…
github-actions commentedon Aug 1, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.