| 1 | import "package:cake_wallet/generated/i18n.dart"; |
| 2 | import "package:cake_wallet/new-ui/widgets/copy_wrapper.dart"; |
| 3 | import "package:cake_wallet/new-ui/widgets/modern_button.dart"; |
| 4 | import "package:flutter/material.dart"; |
| 5 | import "package:flutter/services.dart"; |
| 6 | |
| 7 | class ReceiveBottomButtons extends StatefulWidget { |
| 8 | const ReceiveBottomButtons({ |
| 9 | required this.largeQrMode, |
| 10 | required this.onCopyButtonPressed, |
| 11 | required this.onAccountsButtonPressed, |
| 12 | required this.onAmountButtonPressed, |
| 13 | required this.onLabelButtonPressed, |
| 14 | required this.showLabelButton, |
| 15 | required this.showAccountsButton, |
| 16 | required this.copyData, |
| 17 | super.key, |
| 18 | }); |
| 19 | |
| 20 | final bool largeQrMode; |
| 21 | final ClipboardData? copyData; |
| 22 | final VoidCallback onCopyButtonPressed; |
| 23 | final VoidCallback onAmountButtonPressed; |
| 24 | final VoidCallback onLabelButtonPressed; |
| 25 | final VoidCallback onAccountsButtonPressed; |
| 26 | final bool showLabelButton; |
| 27 | final bool showAccountsButton; |
| 28 | |
| 29 | @override |
| 30 | State<ReceiveBottomButtons> createState() => _ReceiveBottomButtonsState(); |
| 31 | } |
| 32 | |
| 33 | class _ReceiveBottomButtonsState extends State<ReceiveBottomButtons> { |
| 34 | @override |
| 35 | Widget build(BuildContext context) { |
| 36 | final double targetOpacity = widget.largeQrMode ? 0 : 1; |
| 37 | |
| 38 | return ClipRect( |
| 39 | child: AnimatedAlign( |
| 40 | duration: const Duration(milliseconds: 300), |
| 41 | curve: Curves.easeOut, |
| 42 | heightFactor: widget.largeQrMode ? 0 : 1, |
| 43 | alignment: Alignment.bottomCenter, |
| 44 | child: AnimatedOpacity( |
| 45 | duration: const Duration(milliseconds: 300), |
| 46 | opacity: targetOpacity, |
| 47 | curve: Curves.easeOut, |
| 48 | child: Padding( |
| 49 | padding: const EdgeInsets.symmetric(horizontal: 32), |
| 50 | child: Row( |
| 51 | mainAxisSize: MainAxisSize.max, |
| 52 | mainAxisAlignment: MainAxisAlignment.center, |
| 53 | spacing: 16, |
| 54 | children: [ |
| 55 | // The button itself is the only control: it copies when there |
| 56 | // is data to copy, otherwise it opens the payjoin copy modal. |
| 57 | CopyWrapper( |
| 58 | data: widget.copyData, |
| 59 | controlBuilder: (context, copied, onCopy) => AnimatedSwitcher( |
| 60 | duration: const Duration(milliseconds: 200), |
| 61 | child: ModernButton.svg( |
| 62 | key: ValueKey(copied), |
| 63 | size: 60, |
| 64 | iconSize: 32, |
| 65 | svgPath: "assets/new-ui/copy.svg", |
| 66 | onPressed: onCopy ?? widget.onCopyButtonPressed, |
| 67 | label: copied ? S.of(context).copied : S.of(context).copy, |
| 68 | iconColor: copied |
| 69 | ? Theme.of(context).colorScheme.primary |
| 70 | : Theme.of(context).colorScheme.surfaceContainer, |
| 71 | backgroundColor: copied |
| 72 | ? Theme.of(context).colorScheme.surfaceContainerHighest |
| 73 | : Theme.of(context).colorScheme.primary, |
| 74 | ), |
| 75 | ), |
| 76 | ), |
| 77 | ModernButton.svg( |
| 78 | size: 60, |
| 79 | iconSize: 32, |
| 80 | svgPath: "assets/new-ui/set-amount.svg", |
| 81 | onPressed: widget.onAmountButtonPressed, |
| 82 | label: S.of(context).set_amount, |
| 83 | ), |
| 84 | if (widget.showLabelButton) |
| 85 | ModernButton.svg( |
| 86 | size: 60, |
| 87 | iconSize: 32, |
| 88 | svgPath: "assets/new-ui/add-label.svg", |
| 89 | onPressed: widget.onLabelButtonPressed, |
| 90 | label: S.of(context).label, |
| 91 | ), |
| 92 | if (widget.showAccountsButton) |
| 93 | ModernButton.svg( |
| 94 | size: 60, |
| 95 | iconSize: 32, |
| 96 | svgPath: "assets/new-ui/addr-book.svg", |
| 97 | onPressed: widget.onAccountsButtonPressed, |
| 98 | label: S.of(context).addresses, |
| 99 | ), |
| 100 | ], |
| 101 | ), |
| 102 | ), |
| 103 | ), |
| 104 | ), |
| 105 | ); |
| 106 | } |
| 107 | } |