getTextColor method

Color getTextColor (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 buttonTextColor is non-null, then buttonTextColor is returned.

Otherwise the text color depends on the value of getTextTheme and getBrightness.

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;
}