71 lines
2.1 KiB
Dart
71 lines
2.1 KiB
Dart
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 Color? mainColor;
|
|
|
|
const BusyButton({
|
|
required this.title,
|
|
this.busy = false,
|
|
required this.onPressed,
|
|
this.enabled = true,
|
|
this.mainColor,
|
|
});
|
|
|
|
@override
|
|
_BusyButtonState createState() => _BusyButtonState();
|
|
}
|
|
|
|
class _BusyButtonState extends State<BusyButton> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300),
|
|
decoration: BoxDecoration(
|
|
gradient: primaryGradient,
|
|
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: const TextStyle(
|
|
fontWeight: FontWeight.w400,
|
|
color: blackColor,
|
|
fontSize: 12),
|
|
//minFontSize: 2,
|
|
maxLines: 1,
|
|
)
|
|
: SizedBox(
|
|
width: 20.h,
|
|
height: 20.h,
|
|
child: const CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor:
|
|
AlwaysStoppedAnimation<Color>(Colors.white)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|