getTextColor method
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
buttonTextColor
is non-null, then buttonTextColor
is returned.
Otherwise the text color depends on the value of getTextTheme and getBrightness.
- ButtonTextTheme.normal, Colors.white if getBrightness is dark, otherwise Colors.black87.
- ButtonTextTheme.accent],
colorScheme.secondary
. - ButtonTextTheme.primary, if getFillColor is dark then Colors.white,
otherwise if
button
is a FlatButton or an OutlineButton thencolorScheme.primary
, 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;
if (fillIsDark)
return Colors.white;
if (button is FlatButton || button is OutlineButton)
return colorScheme.primary;
return Colors.black;
}
}
assert(false);
return null;
}