-
I am trying to set Container colors as lighter shade of black for dark mode and white for dark mode, but primaryContainer property is not working for it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @zyllus17 and thanks for your question, Despite its name, Here is what the Material 3 guide says about the usage of The You can of course use the theme dependent color @override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).colorScheme.primaryContainer,
child: MyWidget(),
);
} However, for the usage you describe, you may want to consider using
Plus elevation. Here is a Card(
elevation: 4,
surfaceTintColor: colorScheme.surfaceTint,
shadowColor: Colors.transparent, // remove to get shadow
child: const SizedBox(
height: 50,
child: Center(child: Text('Card, elevation 4, no shadow')),
),
), Card is themeable, so you can change the default colors it uses if so desired.
And card in If not using M3, then Card only gets a grey overlay, no primary color tint: Unforuntalty there is only color/shade tint effect on Using Material(
type: MaterialType.card,
elevation: 4,
surfaceTintColor: colorScheme.surfaceTint,
shadowColor: colorScheme.shadow,
child: const SizedBox(
height: 50,
child: Center(
child: Text('Material type card, elevation 4, '
'with shadow')),
),
), It will look like this, in light M3 mode: And like this in M2 light, here the canvas type has a different background tint, since it depends on the background color, instead of surface color, by default and FCS has assigned background a slight primary tint. Where the canvas type gets not grey elevation tint since it has color that differs from surface and only surface colored material gets the elevation grey effect. The canvas type does however have its own background color based tint, making it distinct from the background. The above is actually only Flutter and ThemeData normal behavior, and has nothing really to do with FlexColorScheme, that can only do its magic based on what ThemeData can do. Hope this answers your question, if not please let me know if I can clarify further. I'm going to transfer this to an discussion as a question, as it is more of general theming question than issue. |
Beta Was this translation helpful? Give feedback.
Hi @zyllus17 and thanks for your question,
Despite its name,
ColorScheme.primaryContainer
is not a color used as light or dark color background for Flutter'sContainer
widget by default in any way.Here is what the Material 3 guide says about the usage of
primaryContainer
color:"Primary container is applied to elements needing less emphasis than primary". To learn more about what that means see https://m3.material.io/styles/color/the-color-system/color-roles
The
Container
widget does not have a themedColor
property or even a defaultColor
, so it cannot be affected byThemeData
at all, and thus not by FlexColorScheme either that returns ThemeData.Container
is typically used as lower lev…