estimateErrorBrightness static method
Brightness estimation for error colors that includes fix to consider M2 spec for on M2 dark error color.
Implementation
static Brightness estimateErrorBrightness(Color color) {
// The ThemeData.estimateBrightnessForColor returns dark on the M2
// Material dark mode error colors, but M2 spec uses black onColor on it
// so we should return light to get the correct on color for
// materialDarkError.
if (color == FlexColor.materialDarkError) return Brightness.light;
if (color == FlexColor.materialDarkErrorHc) return Brightness.light;
// Might as well do this as quick return too, estimateBrightnessForColor
// returns same value for this color, but since we will be using this logic
// for error colors we might as well use results for other hard coded color
// values and not call ThemeData.estimateBrightnessForColor
if (color == FlexColor.materialLightError) return Brightness.dark;
if (color == FlexColor.materialLightErrorHc) return Brightness.dark;
// For other error colors we estimate the brightness.
return ThemeData.estimateBrightnessForColor(color);
}