-
Can someone explain me why if I put a container inside a Card with Theme.of(context).colorScheme.surface is not the same color as if I use it on the Card background?
I'm using useMaterial3: true |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @abibiano thanks for the question and for posting it directly here. It is a good question about Material 3 in general that I think other devs will face at some point too. Yes what you describe is indeed the case, but only when Elevation "tint" is a new concept in Material 3 design, where surfaces with higher elevation get an increasing mix of You can read more about the elevation tint design here: https://m3.material.io/styles/elevation/overview To get the same color in M3 on Cards, set the But probably you want to keep the elevation tint of Cards in M3, and you really should, and need that same color somewhere else in your To do so we need to see how the There it uses the Long story short, to give the final ColorScheme scheme = Theme.of(context).colorScheme;
final Color currentBackground = ElevationOverlay.applySurfaceTint(scheme.surface, scheme.surfaceTint, elevation); Where elevation is whatever Material 2 actually use a similar elevation tint, but only in dark mode, it makes higher elevated surfaces and Cards less dark. This only happens if you in Below Hope this helps and answers the question 😄 💙 BR |
Beta Was this translation helpful? Give feedback.
Hi @abibiano thanks for the question and for posting it directly here. It is a good question about Material 3 in general that I think other devs will face at some point too.
Yes what you describe is indeed the case, but only when
useMaterial3
is set to true. This is becauseCard
uses elevation tint and defaults toelevation
1.Elevation "tint" is a new concept in Material 3 design, where surfaces with higher elevation get an increasing mix of
colorScheme.primary
mixed into thesurface
color. The higher the elevation (to a certain point) the higher the mix. Actually the mix color iscolorScheme.surfaceTint
, but it in turn defaults tocolorScheme.primary
here in SDK, tint color can thus als…