toDark method
Returns a new FlexSchemeColor instance based on this one that is suitable for dark mode.
Assumes that the colors this FlexColorScheme is made for are for a light theme, it does not check that current colors actually are so.
Calculates less saturated colors of any colors defined for this
FlexSchemeColor colors, by blending any none null values with white
using given alpha whiteBlend
percentage.
The default whiteBlend
is 35%, this is normally a suitable value.
For more saturated primary color try 40%, which is also used in the
Material design guide to convert the default red error color for
light mode to dark mode. For primary light mode color with low saturation,
a white blend of 20...30% often also produces nice results.
In a Material 3 dark theme, the primary should be lighter than dark
container. Set swapColors
to true, to use the main color as container
color and container as main color, when computing the theme with toDark.
Implementation
FlexSchemeColor toDark([int whiteBlend = 35, bool swapColors = false]) {
if (swapColors) {
return FlexSchemeColor.from(
primary: primaryContainer.blend(Colors.white, whiteBlend),
primaryContainer: primary.blend(Colors.white, whiteBlend),
secondary: secondaryContainer.blend(Colors.white, whiteBlend),
secondaryContainer: secondary.blend(Colors.white, whiteBlend),
tertiary: tertiaryContainer.blend(Colors.white, whiteBlend),
tertiaryContainer: tertiary.blend(Colors.white, whiteBlend),
appBarColor: appBarColor?.blend(Colors.white, whiteBlend),
error: error?.blend(Colors.white, whiteBlend),
errorContainer: errorContainer?.blend(Colors.white, whiteBlend),
swapOnMaterial3: swapOnMaterial3,
);
} else {
return FlexSchemeColor.from(
primary: primary.blend(Colors.white, whiteBlend),
primaryContainer: primaryContainer.blend(Colors.white, whiteBlend),
secondary: secondary.blend(Colors.white, whiteBlend),
secondaryContainer: secondaryContainer.blend(Colors.white, whiteBlend),
tertiary: tertiary.blend(Colors.white, whiteBlend),
tertiaryContainer: tertiaryContainer.blend(Colors.white, whiteBlend),
appBarColor: appBarColor?.blend(Colors.white, whiteBlend),
error: error?.blend(Colors.white, whiteBlend),
errorContainer: errorContainer?.blend(Colors.white, whiteBlend),
swapOnMaterial3: swapOnMaterial3,
);
}
}