import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:gascom/constants/app_theme.dart'; class AppButton extends StatelessWidget { const AppButton({ super.key, required this.onPressed, required this.label, required this.isElevated, this.isLoading = false, this.textStyle, this.color, }); final void Function() onPressed; final String label; final bool isLoading; final bool isElevated; final TextStyle? textStyle; final Color? color; @override Widget build(BuildContext context) { return isElevated ? ElevatedButton( onPressed: isLoading ? null : onPressed, style: Theme.of(context).elevatedButtonTheme.style?.copyWith( backgroundColor: WidgetStatePropertyAll(color ?? AppTheme.textColor), ), child: isLoading ? const Spinner(color: AppTheme.primaryColor) : Row( children: [ Expanded( child: AutoSizeText( label, minFontSize: 8, maxFontSize: 14, maxLines: 1, textAlign: TextAlign.center, style: textStyle ?? Theme.of(context).textTheme.bodyLarge?.copyWith( color: AppTheme.primaryColor, ) ), ), ], ), ) : OutlinedButton( onPressed: isLoading ? null : onPressed, style: Theme.of(context).elevatedButtonTheme.style?.copyWith( backgroundColor: WidgetStatePropertyAll(Theme.of(context).scaffoldBackgroundColor), side: WidgetStatePropertyAll(BorderSide( width: 1.5, color: color ?? AppTheme.textColor, )) ), child: isLoading ? Spinner(color: color ?? AppTheme.textColor,) : Row( children: [ Expanded( child: AutoSizeText( label, minFontSize: 8, maxFontSize: 14, maxLines: 1, textAlign: TextAlign.center, style: textStyle ?? Theme.of(context).textTheme.bodyLarge?.copyWith( color: AppTheme.textColor, ) ), ), ], ), ); } } class Spinner extends StatelessWidget { const Spinner({ super.key, required this.color, }); final Color? color; @override Widget build(BuildContext context) { return SizedBox( width: 20, height: 20, child: CircularProgressIndicator( strokeWidth: 3, color: color ?? Colors.white, ), ); } }