import 'package:flutter/material.dart'; import '../../core/theme/design_tokens.dart'; import 'app_loading_indicator.dart'; class AppButton extends StatelessWidget { const AppButton({ super.key, required this.text, this.onPressed, this.isOutlined = false, this.height = 52, this.isLoading = false, }); final String text; final VoidCallback? onPressed; final bool isOutlined; final double height; final bool isLoading; @override Widget build(BuildContext context) { final colorScheme = Theme.of(context).colorScheme; final isDisabled = onPressed == null || isLoading; if (isOutlined) { return SizedBox( height: height, child: OutlinedButton( onPressed: isLoading ? null : onPressed, style: OutlinedButton.styleFrom( backgroundColor: isDisabled ? colorScheme.secondaryContainer.withValues(alpha: 0.55) : colorScheme.secondaryContainer, foregroundColor: isDisabled ? colorScheme.outline : colorScheme.onSecondaryContainer, side: BorderSide( color: isDisabled ? colorScheme.outlineVariant.withValues(alpha: 0.7) : colorScheme.outlineVariant, ), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppRadius.full), ), padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl), ), child: isLoading ? AppLoadingIndicator( variant: AppLoadingVariant.button, color: colorScheme.onSecondaryContainer, trackColor: colorScheme.outlineVariant, ) : Text( text, style: const TextStyle( fontSize: 15, fontWeight: FontWeight.w700, letterSpacing: 0.2, ), ), ), ); } return DecoratedBox( decoration: BoxDecoration( borderRadius: BorderRadius.circular(AppRadius.full), boxShadow: isDisabled ? const [] : [ BoxShadow( color: colorScheme.primary.withValues(alpha: 0.24), blurRadius: 18, offset: const Offset(0, 10), ), ], ), child: SizedBox( height: height, width: double.infinity, child: ElevatedButton( onPressed: isLoading ? null : onPressed, style: ButtonStyle( elevation: const WidgetStatePropertyAll(0), backgroundColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { return colorScheme.surfaceContainerHighest; } if (states.contains(WidgetState.pressed)) { return colorScheme.primary.withValues(alpha: 0.85); } return colorScheme.primary; }), foregroundColor: WidgetStatePropertyAll(colorScheme.onPrimary), overlayColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.pressed)) { return colorScheme.onPrimary.withValues(alpha: 0.08); } return null; }), shape: WidgetStatePropertyAll( RoundedRectangleBorder( borderRadius: BorderRadius.circular(AppRadius.full), ), ), padding: const WidgetStatePropertyAll( EdgeInsets.symmetric(horizontal: AppSpacing.xl), ), ), child: isLoading ? AppLoadingIndicator( variant: AppLoadingVariant.button, color: colorScheme.onPrimary, trackColor: colorScheme.primaryContainer, ) : Text( text, style: TextStyle( fontSize: 15, fontWeight: FontWeight.w700, letterSpacing: 0.2, color: isDisabled ? colorScheme.outline : colorScheme.onPrimary, ), ), ), ), ); } }