build method

  1. @override
Widget build(
  1. BuildContext context
)
override

UI

Implementation

@override
Widget build(BuildContext context) {
  return SafePress(
    onPressed: onPressed,
    builder: (context, isProcessing, safeOnPressed) {
      return Obx(() {
        final controller = GetIt.I<FontSizeController>();
        final activeShape = controller.actionButtonShape.value;
        final activeStyle = controller.actionButtonStyle.value;
        final activeColorOpt = controller.actionButtonColor.value;

        // 1. Resolve BorderRadius
        final BorderRadius resolvedRadius;
        switch (activeShape) {
          case AppActionButtonShape.pill:
            resolvedRadius = BorderRadius.circular(30.0);
            break;
          case AppActionButtonShape.rounded:
            resolvedRadius = BorderRadius.circular(8.0);
            break;
          case AppActionButtonShape.sharp:
            resolvedRadius = BorderRadius.zero;
            break;
        }

        // 2. Resolve Base Color
        final Color baseColor;
        switch (activeColorOpt) {
          case AppActionButtonColor.accent:
            baseColor = controller.getEffectiveAccentColor();
            break;
          case AppActionButtonColor.grey:
            baseColor = const Color(0xFF64748B); // Slate Grey
            break;
          case AppActionButtonColor.monochrome:
            baseColor = Theme.of(context).brightness == Brightness.dark
                ? Colors.white
                : const Color(0xFF0F172A);
            break;
        }

        // 3. Resolve Background and Icon Colors, and Border based on Style
        Color finalBgColor;
        Color finalIconColor;
        BorderSide finalBorderSide;

        switch (activeStyle) {
          case AppActionButtonStyle.filled:
            finalBgColor = baseColor;
            finalIconColor = baseColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
            finalBorderSide = BorderSide.none;
            break;
          case AppActionButtonStyle.outlined:
            finalBgColor = Colors.transparent;
            finalIconColor = baseColor;
            finalBorderSide = BorderSide(color: baseColor, width: 0.5);
            break;
          case AppActionButtonStyle.flat:
            finalBgColor = Colors.transparent;
            finalIconColor = baseColor;
            finalBorderSide = BorderSide.none;
            break;
        }

        // Apply constructor overrides
        final resolvedBg = backgroundColor ?? finalBgColor;
        final resolvedIconColor = iconColor ?? finalIconColor;

        return Container(
          height: height,
          width: width,
          margin: const EdgeInsets.only(right: 5.0),
          child: Tooltip(
            message: tooltip,
            child: Material(
              color: isProcessing ? resolvedBg.withOpacity(0.5) : resolvedBg,
              shape: RoundedRectangleBorder(
                borderRadius: resolvedRadius,
                side: finalBorderSide,
              ),
              child: InkWell(
                borderRadius: resolvedRadius,
                onTap: safeOnPressed,
                child: Center(
                  child: Icon(
                    icon,
                    size: iconSize,
                    color: isProcessing ? resolvedIconColor.withOpacity(0.5) : resolvedIconColor,
                  ),
                ),
              ),
            ),
          ),
        );
      });
    },
  );
}