93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
|
import 'package:aman_kassa_flutter/shared/shared_styles.dart';
|
|
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.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;
|
|
final IconData icon;
|
|
|
|
const BusyButton(
|
|
{@required this.title,
|
|
this.busy = false,
|
|
@required this.onPressed,
|
|
this.enabled = true,
|
|
this.mainColor,
|
|
this.icon});
|
|
|
|
@override
|
|
_BusyButtonState createState() => _BusyButtonState();
|
|
}
|
|
|
|
class _BusyButtonState extends State<BusyButton> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300),
|
|
decoration: BoxDecoration(
|
|
color: widget.enabled
|
|
? (widget.mainColor ?? primaryColor)
|
|
: widget.mainColor?.withOpacity(0.2) ??
|
|
primaryColor.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(7),
|
|
boxShadow: [cardShadowBox]),
|
|
child: Material(
|
|
type: MaterialType.transparency,
|
|
child: InkWell(
|
|
onTap: widget.busy || !widget.enabled ? null : widget.onPressed,
|
|
child: AnimatedContainer(
|
|
height: widget.busy ? 45 : 45,
|
|
//width: widget.busy ? 40 : 40,
|
|
duration: const Duration(milliseconds: 300),
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0
|
|
//horizontal: widget.busy ? 10 : 10,
|
|
//vertical: widget.busy ? 10 : 10
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
!widget.busy
|
|
? Expanded(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
widget.icon != null
|
|
? Container(
|
|
child: (Icon(
|
|
widget.icon,
|
|
color: whiteColor,
|
|
)),
|
|
margin: const EdgeInsets.only(right: 10.0),
|
|
)
|
|
: (Container()),
|
|
AutoSizeText(
|
|
widget.title,
|
|
textAlign: TextAlign.center,
|
|
style: buttonTitleTextStyle,
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: SizedBox(
|
|
width: 30,
|
|
height: 30,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor:
|
|
AlwaysStoppedAnimation<Color>(Colors.white)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|