| 1 | import 'package:cake_wallet/src/screens/receive/widgets/address_list.dart'; |
| 2 | import 'package:cake_wallet/src/widgets/gradient_background.dart'; |
| 3 | import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; |
| 4 | import 'package:cake_wallet/utils/share_util.dart'; |
| 5 | import 'package:flutter/material.dart'; |
| 6 | import 'package:cake_wallet/generated/i18n.dart'; |
| 7 | import 'package:cake_wallet/src/screens/base_page.dart'; |
| 8 | import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart'; |
| 9 | import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart'; |
| 10 | import 'package:keyboard_actions/keyboard_actions.dart'; |
| 11 | |
| 12 | class ReceivePage extends BasePage { |
| 13 | ReceivePage({required this.addressListViewModel}) |
| 14 | : _cryptoAmountFocus = FocusNode(), |
| 15 | _amountController = TextEditingController(), |
| 16 | _formKey = GlobalKey<FormState>() { |
| 17 | _amountController.addListener(() { |
| 18 | if (_formKey.currentState!.validate()) { |
| 19 | addressListViewModel.changeAmount(_amountController.text); |
| 20 | } |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | final WalletAddressListViewModel addressListViewModel; |
| 25 | final TextEditingController _amountController; |
| 26 | final GlobalKey<FormState> _formKey; |
| 27 | static const _heroTag = 'receive_page'; |
| 28 | |
| 29 | @override |
| 30 | String get title => S.current.receive; |
| 31 | |
| 32 | @override |
| 33 | bool get gradientBackground => true; |
| 34 | |
| 35 | @override |
| 36 | bool get resizeToAvoidBottomInset => true; |
| 37 | |
| 38 | final FocusNode _cryptoAmountFocus; |
| 39 | |
| 40 | @override |
| 41 | Widget middle(BuildContext context) { |
| 42 | return Text( |
| 43 | title, |
| 44 | style: Theme.of(context).textTheme.titleMedium?.copyWith( |
| 45 | fontSize: 18.0, |
| 46 | fontWeight: FontWeight.bold, |
| 47 | color: pageIconColor(context), |
| 48 | ), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | @override |
| 53 | Widget Function(BuildContext, Widget) get rootWrapper => |
| 54 | (BuildContext context, Widget scaffold) => GradientBackground(scaffold: scaffold); |
| 55 | |
| 56 | @override |
| 57 | Widget trailing(BuildContext context) { |
| 58 | return Material( |
| 59 | color: Colors.transparent, |
| 60 | child: Semantics( |
| 61 | label: S.of(context).share, |
| 62 | child: IconButton( |
| 63 | padding: EdgeInsets.zero, |
| 64 | constraints: BoxConstraints(), |
| 65 | highlightColor: Colors.transparent, |
| 66 | splashColor: Colors.transparent, |
| 67 | iconSize: 25, |
| 68 | onPressed: () => ShareUtil.share( |
| 69 | text: addressListViewModel.uri.toString(), |
| 70 | context: context, |
| 71 | ), |
| 72 | icon: Icon( |
| 73 | Icons.share, |
| 74 | size: 20, |
| 75 | color: pageIconColor(context), |
| 76 | ), |
| 77 | ), |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | @override |
| 83 | Widget body(BuildContext context) => KeyboardActions( |
| 84 | config: KeyboardActionsConfig( |
| 85 | keyboardActionsPlatform: KeyboardActionsPlatform.IOS, |
| 86 | keyboardBarColor: Theme.of(context).colorScheme.surface, |
| 87 | nextFocus: false, |
| 88 | actions: [ |
| 89 | KeyboardActionsItem( |
| 90 | focusNode: _cryptoAmountFocus, |
| 91 | toolbarButtons: [(_) => KeyboardDoneButton()], |
| 92 | ) |
| 93 | ]), |
| 94 | child: SingleChildScrollView( |
| 95 | child: Column( |
| 96 | children: <Widget>[ |
| 97 | Padding( |
| 98 | padding: EdgeInsets.fromLTRB(24, 50, 24, 24), |
| 99 | child: QRWidget( |
| 100 | addressListViewModel: addressListViewModel, |
| 101 | formKey: _formKey, |
| 102 | heroTag: _heroTag, |
| 103 | amountTextFieldFocusNode: _cryptoAmountFocus, |
| 104 | amountController: _amountController, |
| 105 | ), |
| 106 | ), |
| 107 | AddressList(addressListViewModel: addressListViewModel), |
| 108 | Padding( |
| 109 | padding: EdgeInsets.fromLTRB(24, 24, 24, 32), |
| 110 | child: Text( |
| 111 | addressListViewModel.isSilentPayments |
| 112 | ? S.of(context).silent_payments_disclaimer |
| 113 | : S.of(context).electrum_address_disclaimer, |
| 114 | textAlign: TextAlign.center, |
| 115 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 116 | fontSize: 15, |
| 117 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 118 | ), |
| 119 | ), |
| 120 | ), |
| 121 | ], |
| 122 | ), |
| 123 | ), |
| 124 | ); |
| 125 | } |