getBackgroundColor method

Color? getBackgroundColor(
  1. BuildContext context,
  2. ButtonState state,
  3. Color? fillColor
)

Implementation

Color? getBackgroundColor(
  BuildContext context,
  ButtonState state,
  Color? fillColor,
) {
  final isDark = context.isDark;
  final theme = context.fluffyTheme;
  switch (this) {
    /// ButtonVariant.primary.
    case ButtonVariant.primary:
      final baseColor = fillColor ?? theme.colors.primary;
      if (state == ButtonState.disabled) {
        return baseColor.withValues(alpha: 0.5);
      }
      if (state == ButtonState.hover) {
        return baseColor.withValues(alpha: 0.8);
      }
      return baseColor;

    /// ButtonVariant.ghost.
    case ButtonVariant.ghost:
      if (state == ButtonState.hover || state == ButtonState.pressing) {
        final baseColor = isDark
            ? theme.colors.neutral5
            : theme.colors.neutral3;
        if (fillColor != null) {
          return Color.lerp(
            isDark ? theme.colors.neutral7 : theme.colors.neutral1,
            fillColor,
            0.25,
          );
        }
        return baseColor;
      }
      return isDark ? theme.colors.neutral7 : theme.colors.neutral1;

    /// ButtonVariant.secondary.
    case ButtonVariant.secondary:
      final baseColor =
          fillColor ??
          (isDark ? theme.colors.neutral1 : theme.colors.neutral7);
      if (state == ButtonState.disabled) {
        return baseColor.withValues(alpha: 0.5);
      }
      return baseColor;
  }
}