buildButtonStyle static method

ButtonStyle buildButtonStyle(
  1. TWidgetTheme baseTheme,
  2. TButtonShape shape,
  3. TSize size, {
  4. double? elevation,
  5. Color? shadowColor,
})

Implementation

static ButtonStyle buildButtonStyle(
  TWidgetTheme baseTheme,
  TButtonShape shape,
  TSize size, {
  double? elevation,
  Color? shadowColor,
}) {
  final padding = switch (shape) {
    TButtonShape.tile => size.tilePaddingState,
    _ => size.paddingState,
  };

  final isFill = baseTheme.type == TVariant.solid ||
      (!baseTheme.container.isTransparent && baseTheme.type != TVariant.outline && baseTheme.type != TVariant.text);

  final defaultElevation = isFill ? (baseTheme.type == TVariant.solid ? 1.0 : 0.5) : 0.0;
  final effectiveElevation = elevation ?? defaultElevation;

  return ButtonStyle(
    backgroundColor: baseTheme.backgroundState,
    foregroundColor: baseTheme.foregroundState,
    iconColor: baseTheme.foregroundState,
    side: baseTheme.borderSideState,
    padding: padding,
    minimumSize: size.minimumSizeState,
    visualDensity: VisualDensity.standard,
    overlayColor: WidgetStateProperty.resolveWith((states) {
      if (states.contains(WidgetState.disabled)) return Colors.transparent;
      if (states.contains(WidgetState.pressed)) {
        return Colors.black.withValues(alpha: baseTheme.isDarkMode ? 0.10 : 0.06);
      }
      if (states.contains(WidgetState.hovered)) {
        return Colors.white.withValues(alpha: baseTheme.isDarkMode ? 0.08 : 0.10);
      }
      return Colors.transparent;
    }),
    elevation: WidgetStateProperty.resolveWith((states) {
      if (states.contains(WidgetState.disabled)) return 0.0;
      if (!isFill && elevation == null) return 0.0;
      if (states.contains(WidgetState.pressed)) return (effectiveElevation * 0.5).clamp(0.0, 1.0);
      if (states.contains(WidgetState.hovered)) return effectiveElevation + 1.0;
      return effectiveElevation;
    }),
    shadowColor: WidgetStateProperty.resolveWith((states) {
      if (!isFill && shadowColor == null) return Colors.transparent;
      final shadow = shadowColor ?? baseTheme.shadow ?? baseTheme.color.shade(900);
      return shadow.withValues(alpha: 0.18);
    }),
    textStyle: WidgetStateProperty.all(TextStyle(fontSize: size.font, fontWeight: baseTheme.type.fontWeight, letterSpacing: 0.65)),
    shape: WidgetStateProperty.all(shape.border),
  );
}