getStateOverlay method

Color getStateOverlay(
  1. Color base,
  2. UIState state, [
  3. Color? background
])

Returns the state overlay color for the base on the background.

ColorScheme.canvas is used if background is not given.

Implementation

Color getStateOverlay(Color base, UIState state, [Color? background]) {
  final isTransparentOrWhite = base.a == 0 || base.toARGB32() == 0xFFFFFFFF;

  if (isTransparentOrWhite) {
    return const Color(0xFFF7F7F7);
  }

  final opacity = switch (state) {
    UIState.hovered => stateHoverOpacity,
    UIState.pressed => statePressedOpacity,
    UIState.focused => stateFocusOpacity,
    UIState.disabled => stateDisabledOpacity,
    UIState.selected => statePressedOpacity,
  };

  return Color.alphaBlend(base.withValues(alpha: opacity), background ?? canvas);
}