backgroundButtonStyle function

ButtonStyle backgroundButtonStyle(
  1. Palette sc, {
  2. bool showBorder = false,
  3. TextStyle? textStyle,
  4. double borderWidth = 2,
  5. OutlinedBorder? shape,
  6. required double scale,
})

Implementation

ButtonStyle backgroundButtonStyle(
  Palette sc, {
  bool showBorder = false,
  TextStyle? textStyle,
  double borderWidth = 2,
  OutlinedBorder? shape,
  required double scale,
}) {
  return ButtonStyle(
    animationDuration: buttonStyleAnimationDuration,
    visualDensity: VisualDensity.compact,
    backgroundColor: widgetPropertyByState(
      normal: () => sc.background,
      hover: () => sc.backgroundHovered,
      splash: () => sc.backgroundSplashed,
    ),
    surfaceTintColor: widgetPropertyByState(
      normal: () => sc.background,
      hover: () => sc.backgroundHovered,
      splash: () => sc.backgroundSplashed,
    ),
    overlayColor: const WidgetStatePropertyAll(Colors.transparent),
    foregroundColor: widgetPropertyByState(
      normal: () => sc.backgroundText,
      hover: () => sc.backgroundHoveredText,
      splash: () => sc.backgroundSplashedText,
    ),
    iconColor: widgetPropertyByState(
      normal: () => sc.backgroundFill,
      hover: () => sc.backgroundHoveredFill,
      splash: () => sc.backgroundSplashedFill,
    ),
    textStyle: textStyle != null ? WidgetStatePropertyAll(textStyle) : null,
    minimumSize: WidgetStatePropertyAll(minimumSizeForScale(scale)),
    maximumSize: WidgetStatePropertyAll(maximumSize),
    padding: WidgetStatePropertyAll(padding),
    shape: shape == null ? null : WidgetStatePropertyAll(shape),
    side: showBorder
        ? WidgetStateProperty.resolveWith((states) {
            if (states.contains(WidgetState.pressed) ||
                states.contains(WidgetState.dragged)) {
              return BorderSide(
                color: sc.backgroundSplashedBorder,
                width: borderWidth,
              );
            }
            if (states.contains(WidgetState.hovered) ||
                states.contains(WidgetState.focused) ||
                states.contains(WidgetState.selected)) {
              return BorderSide(
                color: sc.backgroundHoveredBorder,
                width: borderWidth,
              );
            }
            return BorderSide(color: sc.backgroundBorder, width: borderWidth);
          })
        : null,
  );
}