getTextColor method
- MaterialButton button
The foreground color of the button
's text and icon.
If button
is not MaterialButton.enabled, the value of
getDisabledTextColor is returned. If the button is enabled and
MaterialButton.textColor is non-null, then MaterialButton.textColor
is returned.
Otherwise the text color depends on the value of getTextTheme and getBrightness.
- ButtonTextTheme.normal: Colors.white is used if getBrightness resolves to Brightness.dark. Colors.black87 is used if getBrightness resolves to Brightness.light.
- ButtonTextTheme.accent: ColorScheme.secondary of colorScheme.
- ButtonTextTheme.primary: If getFillColor is dark then Colors.white, otherwise Colors.black.
Implementation
Color getTextColor(MaterialButton button) {
if (!button.enabled) {
return getDisabledTextColor(button);
}
if (button.textColor != null) {
return button.textColor!;
}
switch (getTextTheme(button)) {
case ButtonTextTheme.normal:
return getBrightness(button) == Brightness.dark ? Colors.white : Colors.black87;
case ButtonTextTheme.accent:
return colorScheme!.secondary;
case ButtonTextTheme.primary:
final Color? fillColor = getFillColor(button);
final bool fillIsDark = fillColor != null
? ThemeData.estimateBrightnessForColor(fillColor) == Brightness.dark
: getBrightness(button) == Brightness.dark;
return fillIsDark ? Colors.white : Colors.black;
}
}