primary_button.dart 1.59 KB
import 'package:doublefeel_flutter/core/theme/app_colors.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:flutter/material.dart';

class PrimaryButton extends StatelessWidget {
  const PrimaryButton({
    super.key,
    required this.label,
    required this.enabled,
    required this.loading,
    required this.onTap,
    this.backgroundColor = AppColors.primary,
    this.disabledColor,
  });

  final String label;
  final bool enabled;
  final bool loading;
  final VoidCallback onTap;
  final Color backgroundColor;
  final Color? disabledColor;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: enabled ? onTap : null,
      behavior: HitTestBehavior.opaque,
      child: Container(
        height: 48.h,
        decoration: BoxDecoration(
          color: enabled
              ? backgroundColor
              : disabledColor ?? backgroundColor.withValues(alpha: 0.35),
          borderRadius: BorderRadius.circular(24.dp),
        ),
        alignment: Alignment.center,
        child: loading
            ? const SizedBox(
                width: 18,
                height: 18,
                child: CircularProgressIndicator(
                  strokeWidth: 2,
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
                ),
              )
            : Text(
                label,
                style: const TextStyle(
                  color: Colors.white,
                  fontSize: 14,
                  fontWeight: FontWeight.w500,
                ),
              ),
      ),
    );
  }
}