import 'package:auto_size_text/auto_size_text.dart'; import 'package:baligh/constants/theme.dart'; import 'package:baligh/widgets/small_spinner.dart'; import 'package:flutter/material.dart'; class CustomButton extends StatelessWidget { const CustomButton({ 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 ?? MyCustomTheme.primaryColor) ), child: isLoading ? const SmallSpinner() : Padding( padding: const EdgeInsets.symmetric(horizontal: 3), child: Row( children: [ Expanded( child: AutoSizeText( label, minFontSize: 8, maxFontSize: 14, maxLines: 1, textAlign: TextAlign.center, style: textStyle ?? Theme.of(context).textTheme.bodyLarge?.copyWith( color: MyCustomTheme.bgColor, ) ), ), ], ), ), ) : 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 ?? MyCustomTheme.primaryColor, )) ), child: isLoading ? SmallSpinner(color: MyCustomTheme.primaryColor,) : Padding( padding: const EdgeInsets.symmetric(horizontal: 3), child: Row( children: [ Expanded( child: AutoSizeText( label, minFontSize: 8, maxFontSize: 14, maxLines: 1, textAlign: TextAlign.center, style: textStyle ?? Theme.of(context).textTheme.bodyLarge?.copyWith( color: color ?? MyCustomTheme.primaryColor, ) ), ), ], ), ), ); } }