-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NavigationDrawerDestination items do not follow theme background #219
Comments
Hi @mavriq-dev, Thanks for this report. It is indeed a correct observation, it is also sadly expected behavior with current and latest Flutter version 3.19.2. Let's study it and find out more. We can repeat the same issue without import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: theme(),
home: Scaffold(
appBar: AppBar(),
drawer: getNavDrawer(),
body: const Center(
child: Text('Hello World!'),
),
),
);
}
}
NavigationDrawer getNavDrawer() {
return const NavigationDrawer(children: [
NavigationDrawerDestination(
icon: Icon(Icons.close), label: Text('Destination 1')),
NavigationDrawerDestination(
icon: Icon(Icons.close), label: Text('Destination 2')),
NavigationDrawerDestination(
icon: Icon(Icons.close), label: Text('Destination 3'))
]);
}
ColorScheme scheme = ColorScheme.fromSeed(seedColor: Color(0xFF6750A4));
ThemeData theme() => ThemeData(
colorScheme: scheme,
navigationDrawerTheme: NavigationDrawerThemeData(
backgroundColor: scheme.surface,
),
);
And it looks the same: So why does this happen? It is because the However, the ThemeData theme() => ThemeData(
colorScheme: scheme,
navigationDrawerTheme: NavigationDrawerThemeData(
backgroundColor: scheme.surface,
elevation: 0,
),
); The colors match: But what if I want to use e.g. elevation 12? It would then look like this: Not pretty and probably not what was expected either! The simple workaround is to make the import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: theme(),
home: Scaffold(
appBar: AppBar(),
drawer: getNavDrawer(),
body: const Center(
child: Text('Hello World!'),
),
),
);
}
}
NavigationDrawer getNavDrawer() {
return const NavigationDrawer(children: [
NavigationDrawerDestination(
backgroundColor: Colors.transparent,
icon: Icon(Icons.close),
label: Text('Destination 1')),
NavigationDrawerDestination(
backgroundColor: Colors.transparent,
icon: Icon(Icons.close),
label: Text('Destination 2')),
NavigationDrawerDestination(
backgroundColor: Colors.transparent,
icon: Icon(Icons.close),
label: Text('Destination 3'))
]);
}
ColorScheme scheme = ColorScheme.fromSeed(seedColor: const Color(0xFF6750A4));
ThemeData theme() => ThemeData(
colorScheme: scheme,
navigationDrawerTheme: NavigationDrawerThemeData(
backgroundColor: scheme.surface,
elevation: 12,
),
);
But we are using themes and should not need to think about such things. Here is a really interesting part. The published Themes Playground app does not do this with the It looks like you showed: and I double checked, I don't do any transparent color on the destinations in its code. Wait, what is going on here? Well Themes Playground live version was built back with Flutter SDK 3.13.1: If I build it with latest Flutter SDK 3.19.2: I get the same result and yes imo issue too! As we already established this is what it looks like now with vanilla Flutter 3.19.2 as well. So it is not a FlexColorScheme issue. What has happened?Between Flutter version 3.13.1 and 3.19.2, somewhere along the way there was a change that caused this issue. It is perhaps an intentional change, but potentially also a regression. The change has probably been caused by the color being transparent on the https://m3.material.io/components/navigation-drawer/specs Well actually the spec says it should be token All the elevation tints are going away in Material3 and Flutter too, in favor of precomputed surface shades for different usages. The token So if we would have that token color as background color and no elevation tint anymore, the new theme defaults would work and the colors would match, but since we don't, one gets elevation tint (drawer) and the destinations do not, and hence the colors do not match. So yes, I think it is a Flutter bug/regression with too eager implementation of component theme behavior from token db, before Flutter actually support the needed new colors and behavior. There is PR in Flutter SDK that is preparing the theme for massive changes. I tweeted about it here: https://x.com/RydMike/status/1761057220047909295?s=20 ConclusionSadly since this is a Flutter SDK issue and regression, there is not much I can do about it to fix it in FlexColorScheme. I will check if the issue has been reported in Flutter issues and report it as regression, if does not exist. I need to find the stable Flutter version where it broke. I have not seen any breaking change notification about this, so it should at least be considered a regression. BTW, thanks for the report, a very good find! 👍🏻 😄 💙 |
Even if this is "Flutter SDK" sourced and there is not much I can do about it here. I will keep it open so other can discover and learn about it too. And I will link issue and progress in Flutter repo as well. I will also add it as known Flutter theming issues on my FlexColorScheme docs site. |
Cool. At least I know why it happens and how to work around it. Thanks for the great explanation! |
The background color of NavigationDrawerDestination items do not follow the theme and the simulator.
This is how the them appears:
In the simlator it looks like this:
I took the theme code directly from the playground.
Example Code:
The text was updated successfully, but these errors were encountered: