dev
dart 141 lines 5.62 KB
Raw
1 import 'package:cake_wallet/core/email_validator.dart';
2 import 'package:cake_wallet/generated/i18n.dart';
3 import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker.dart';
4 import 'package:cake_wallet/src/screens/receive/widgets/anonpay_currency_input_field.dart';
5 import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
6 import 'package:cake_wallet/utils/show_pop_up.dart';
7 import 'package:cake_wallet/view_model/anon_invoice_page_view_model.dart';
8 import 'package:flutter/material.dart';
9 import 'package:flutter_mobx/flutter_mobx.dart';
10
11 class AnonInvoiceForm extends StatelessWidget {
12 AnonInvoiceForm({
13 super.key,
14 required this.formKey,
15 required this.anonInvoicePageViewModel,
16 required this.isInvoice,
17 required this.amountController,
18 required this.nameController,
19 required this.emailController,
20 required this.descriptionController,
21 required this.depositAmountFocus,
22 }) : _nameFocusNode = FocusNode(),
23 _emailFocusNode = FocusNode(),
24 _descriptionFocusNode = FocusNode() {
25 amountController.text = anonInvoicePageViewModel.amount;
26 nameController.text = anonInvoicePageViewModel.receipientName;
27 descriptionController.text = anonInvoicePageViewModel.description;
28 emailController.text = anonInvoicePageViewModel.receipientEmail;
29 }
30
31 final TextEditingController amountController;
32 final TextEditingController nameController;
33 final TextEditingController emailController;
34 final TextEditingController descriptionController;
35 final AnonInvoicePageViewModel anonInvoicePageViewModel;
36 final FocusNode depositAmountFocus;
37 final FocusNode _nameFocusNode;
38 final FocusNode _emailFocusNode;
39 final FocusNode _descriptionFocusNode;
40 final GlobalKey<FormState> formKey;
41 final bool isInvoice;
42
43 @override
44 Widget build(BuildContext context) {
45 return Form(
46 key: formKey,
47 child: Column(
48 crossAxisAlignment: CrossAxisAlignment.start,
49 children: <Widget>[
50 Text(
51 isInvoice ? S.of(context).invoice_details : S.of(context).donation_link_details,
52 style: Theme.of(context).textTheme.titleMedium?.copyWith(
53 fontWeight: FontWeight.w600,
54 ),
55 ),
56 if (isInvoice)
57 Observer(
58 builder: (_) {
59 return AnonpayCurrencyInputField(
60 onTapPicker: () => _presentPicker(context),
61 controller: amountController,
62 focusNode: depositAmountFocus,
63 maxAmount: anonInvoicePageViewModel.maximum?.toString() ?? '...',
64 minAmount: anonInvoicePageViewModel.minimum?.toString() ?? '...',
65 selectedCurrency: anonInvoicePageViewModel.selectedCurrency,
66 );
67 },
68 ),
69 SizedBox(height: 24),
70 BaseTextFormField(
71 hasUnderlineBorder: true,
72 controller: nameController,
73 focusNode: _nameFocusNode,
74 suffixIcon: SizedBox(width: 36),
75 hintText: S.of(context).optional_name,
76 textInputAction: TextInputAction.next,
77 placeholderTextStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
78 fontWeight: FontWeight.w600,
79 color: Theme.of(context).colorScheme.onSurfaceVariant,
80 ),
81 textStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
82 fontWeight: FontWeight.w600,
83 color: Theme.of(context).colorScheme.onSurface,
84 ),
85 validator: null,
86 ),
87 SizedBox(height: 24),
88 BaseTextFormField(
89 hasUnderlineBorder: true,
90 controller: descriptionController,
91 focusNode: _descriptionFocusNode,
92 textInputAction: TextInputAction.next,
93 suffixIcon: SizedBox(width: 36),
94 hintText: S.of(context).optional_description,
95 placeholderTextStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
96 fontWeight: FontWeight.w600,
97 color: Theme.of(context).colorScheme.onSurfaceVariant,
98 ),
99 textStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
100 fontWeight: FontWeight.w600,
101 color: Theme.of(context).colorScheme.onSurface,
102 ),
103 validator: null,
104 ),
105 SizedBox(height: 24),
106 BaseTextFormField(
107 hasUnderlineBorder: true,
108 controller: emailController,
109 textInputAction: TextInputAction.next,
110 focusNode: _emailFocusNode,
111 suffixIcon: SizedBox(width: 36),
112 keyboardType: TextInputType.emailAddress,
113 hintText: S.of(context).optional_email_hint,
114 placeholderTextStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
115 fontWeight: FontWeight.w600,
116 color: Theme.of(context).colorScheme.onSurfaceVariant,
117 ),
118 textStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
119 fontWeight: FontWeight.w600,
120 color: Theme.of(context).colorScheme.onSurface,
121 ),
122 validator: EmailValidator(),
123 ),
124 SizedBox(height: 52),
125 ],
126 ),
127 );
128 }
129
130 void _presentPicker(BuildContext context) {
131 showPopUp<void>(
132 builder: (_) => CurrencyPicker(
133 selectedAtIndex: anonInvoicePageViewModel.selectedCurrencyIndex,
134 items: anonInvoicePageViewModel.currencies,
135 hintText: S.of(context).search_currency,
136 onItemSelected: anonInvoicePageViewModel.selectCurrency,
137 ),
138 context: context,
139 );
140 }
141 }