import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:satu/shared/app_colors.dart'; import 'package:satu/shared/shared_styles.dart'; /// A button that shows a busy indicator in place of title class BusyButton extends StatefulWidget { final bool busy; final String title; final Function onPressed; final bool enabled; final bool isCancel; final bool isDanger; const BusyButton({ required this.title, this.busy = false, required this.onPressed, this.enabled = true, this.isCancel = false, this.isDanger = false, }); @override _BusyButtonState createState() => _BusyButtonState(); } class _BusyButtonState extends State { @override Widget build(BuildContext context) { return AnimatedContainer( duration: const Duration(milliseconds: 300), decoration: BoxDecoration( gradient: widget.isCancel || widget.isDanger ? null : primaryGradient, color: widget.isCancel || widget.isDanger ? whiteColor : null, borderRadius: BorderRadius.circular(5), boxShadow: [buttonShadowBox]), child: Material( type: MaterialType.transparency, child: InkWell( onTap: () { if (!(widget.busy || !widget.enabled)) widget.onPressed(); }, child: AnimatedContainer( height: 40.h, duration: const Duration(milliseconds: 300), alignment: Alignment.center, child: !widget.busy ? Text( widget.title, textAlign: TextAlign.center, style: TextStyle( fontWeight: FontWeight.w400, color: widget.isDanger ? dangerColor : blackColor, fontSize: 12), //minFontSize: 2, maxLines: 1, ) : SizedBox( width: 20.h, height: 20.h, child: const CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white)), ), ), ), ), ); } }