getFillColor method Null safety

Color? getFillColor(
  1. MaterialButton button
)

The button's background fill color or null for buttons that don't have a background color.

Returns MaterialButton.color if it is non-null and the button is enabled.

Otherwise, returns MaterialButton.disabledColor if it is non-null and the button is disabled.

Otherwise, if button is a FlatButton then null is returned.

Otherwise, if button is a RaisedButton, returns the buttonColor constructor parameter if it was non-null and the button is enabled.

Otherwise the fill color depends on the value of getTextTheme.

Implementation

Color? getFillColor(MaterialButton button) {
  final Color? fillColor = button.enabled ? button.color : button.disabledColor;
  if (fillColor != null)
    return fillColor;

  if (button is FlatButton || button.runtimeType == MaterialButton)
    return null;

  if (button.enabled && button is RaisedButton && _buttonColor != null)
    return _buttonColor;

  switch (getTextTheme(button)) {
    case ButtonTextTheme.normal:
    case ButtonTextTheme.accent:
      return button.enabled ? colorScheme!.primary : getDisabledFillColor(button);
    case ButtonTextTheme.primary:
      return button.enabled
        ? _buttonColor ?? colorScheme!.primary
        : colorScheme!.onSurface.withOpacity(0.12);
  }
}