| 1 | import "package:cake_wallet/new-ui/widgets/new_primary_button.dart"; |
| 2 | import "package:flutter/material.dart"; |
| 3 | import "package:flutter_svg/flutter_svg.dart"; |
| 4 | |
| 5 | class NewFuturePrimaryButton extends StatefulWidget { |
| 6 | const NewFuturePrimaryButton({ |
| 7 | required this.onPressed, |
| 8 | required this.text, |
| 9 | required this.color, |
| 10 | required this.textColor, |
| 11 | this.borderColor = Colors.transparent, |
| 12 | this.disabled = false, |
| 13 | this.image, |
| 14 | super.key, |
| 15 | }); |
| 16 | |
| 17 | final Future<void> Function() onPressed; |
| 18 | final bool disabled; |
| 19 | final SvgPicture? image; |
| 20 | final Color color; |
| 21 | final Color textColor; |
| 22 | final Color borderColor; |
| 23 | final String text; |
| 24 | |
| 25 | @override |
| 26 | State<StatefulWidget> createState() => _NewFuturePrimaryButtonState(); |
| 27 | } |
| 28 | |
| 29 | class _NewFuturePrimaryButtonState extends State<NewFuturePrimaryButton> { |
| 30 | bool isLoading = false; |
| 31 | |
| 32 | Future<void> _onPressed() async { |
| 33 | if (isLoading) { |
| 34 | return; |
| 35 | } |
| 36 | setState(() => isLoading = true); |
| 37 | try { |
| 38 | await widget.onPressed.call(); |
| 39 | } finally { |
| 40 | if (mounted) { |
| 41 | setState(() => isLoading = false); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | @override |
| 47 | Widget build(BuildContext context) => NewPrimaryButton( |
| 48 | onPressed: _onPressed, |
| 49 | image: widget.image, |
| 50 | text: widget.text, |
| 51 | color: widget.color, |
| 52 | textColor: widget.textColor, |
| 53 | isLoading: isLoading, |
| 54 | borderColor: widget.borderColor, |
| 55 | disabled: widget.disabled, |
| 56 | ); |
| 57 | } |