12
import 'package:cake_wallet/utils/permission_handler.dart';
13
import 'package:permission_handler/permission_handler.dart';
14
15
-enum AddressTextFieldOption { paste, qrCode, addressBook }
15
+enum AddressTextFieldOption { paste, qrCode, addressBook, walletAddresses }
16
17
class AddressTextField extends StatelessWidget {
18
AddressTextField(
34
this.validator,
35
this.onPushPasteButton,
36
this.onPushAddressBookButton,
37
+ this.onPushAddressPickerButton,
38
this.onSelectedContact,
39
this.selectedCurrency});
40
57
final FocusNode? focusNode;
58
final Function(BuildContext context)? onPushPasteButton;
59
final Function(BuildContext context)? onPushAddressBookButton;
60
+ final Function(BuildContext context)? onPushAddressPickerButton;
61
final Function(ContactBase contact)? onSelectedContact;
62
final CryptoCurrency? selectedCurrency;
63
72
enabled: isActive,
73
controller: controller,
74
focusNode: focusNode,
73
-
75
style: textStyle ??
76
TextStyle(
77
fontSize: 16, color: Theme.of(context).extension<CakeTextTheme>()!.titleColor),
78
decoration: InputDecoration(
78
-
79
suffixIcon: SizedBox(
80
width: prefixIconWidth * options.length + (spaceBetweenPrefixIcons * options.length),
81
),
82
-
82
hintStyle: hintStyle ?? TextStyle(fontSize: 16, color: Theme.of(context).hintColor),
83
hintText: placeholder ?? S.current.widgets_address,
84
focusedBorder: isBorderExist
103
top: 2,
104
right: 0,
105
child: SizedBox(
107
- width: prefixIconWidth * options.length + (spaceBetweenPrefixIcons * options.length),
106
+ width:
107
+ (prefixIconWidth * options.length) + (spaceBetweenPrefixIcons * options.length),
108
child: Row(
109
mainAxisAlignment: responsiveLayoutUtil.shouldRenderMobileUI
110
? MainAxisAlignment.spaceBetween
111
: MainAxisAlignment.end,
112
children: [
113
- SizedBox(width: 5),
113
if (this.options.contains(AddressTextFieldOption.paste)) ...[
114
+ SizedBox(width: 5),
115
Container(
116
- width: prefixIconWidth,
117
- height: prefixIconHeight,
118
- padding: EdgeInsets.only(top: 0),
119
- child: Semantics(
120
- label: S.of(context).paste,
121
- child: InkWell(
122
- onTap: () async => _pasteAddress(context),
123
- child: Container(
124
- padding: EdgeInsets.all(8),
125
- decoration: BoxDecoration(
126
- color: buttonColor ??
127
- Theme.of(context).dialogTheme.backgroundColor,
128
- borderRadius: BorderRadius.all(Radius.circular(6))),
129
- child: Image.asset(
130
- 'assets/images/paste_ios.png',
131
- color: iconColor ??
132
- Theme.of(context)
133
- .extension<SendPageTheme>()!
134
- .textFieldButtonIconColor,
135
- )),
136
- ),
137
- )),
116
+ width: prefixIconWidth,
117
+ height: prefixIconHeight,
118
+ padding: EdgeInsets.only(top: 0),
119
+ child: Semantics(
120
+ label: S.of(context).paste,
121
+ child: InkWell(
122
+ onTap: () async => _pasteAddress(context),
123
+ child: Container(
124
+ padding: EdgeInsets.all(8),
125
+ decoration: BoxDecoration(
126
+ color:
127
+ buttonColor ?? Theme.of(context).dialogTheme.backgroundColor,
128
+ borderRadius: BorderRadius.all(Radius.circular(6))),
129
+ child: Image.asset(
130
+ 'assets/images/paste_ios.png',
131
+ color: iconColor ??
132
+ Theme.of(context)
133
+ .extension<SendPageTheme>()!
134
+ .textFieldButtonIconColor,
135
+ )),
136
+ ),
137
+ ),
138
+ ),
139
],
140
if (this.options.contains(AddressTextFieldOption.qrCode) &&
141
DeviceInfo.instance.isMobile) ...[
141
- Container(
142
- width: prefixIconWidth,
143
- height: prefixIconHeight,
144
- padding: EdgeInsets.only(top: 0),
145
- child: Semantics(
146
- label: S.of(context).scan_qr_code,
147
- child: InkWell(
148
- onTap: () async => _presentQRScanner(context),
149
- child: Container(
150
- padding: EdgeInsets.all(8),
151
- decoration: BoxDecoration(
152
- color: buttonColor ??
153
- Theme.of(context).dialogTheme.backgroundColor,
154
- borderRadius: BorderRadius.all(Radius.circular(6))),
155
- child: Image.asset(
156
- 'assets/images/qr_code_icon.png',
157
- color: iconColor ??
158
- Theme.of(context)
159
- .extension<SendPageTheme>()!
160
- .textFieldButtonIconColor,
161
- )),
162
- ),
163
- ))
164
- ] else
142
SizedBox(width: 5),
143
+ Container(
144
+ width: prefixIconWidth,
145
+ height: prefixIconHeight,
146
+ padding: EdgeInsets.only(top: 0),
147
+ child: Semantics(
148
+ label: S.of(context).scan_qr_code,
149
+ child: InkWell(
150
+ onTap: () async => _presentQRScanner(context),
151
+ child: Container(
152
+ padding: EdgeInsets.all(8),
153
+ decoration: BoxDecoration(
154
+ color:
155
+ buttonColor ?? Theme.of(context).dialogTheme.backgroundColor,
156
+ borderRadius: BorderRadius.all(Radius.circular(6))),
157
+ child: Image.asset(
158
+ 'assets/images/qr_code_icon.png',
159
+ color: iconColor ??
160
+ Theme.of(context)
161
+ .extension<SendPageTheme>()!
162
+ .textFieldButtonIconColor,
163
+ )),
164
+ ),
165
+ ),
166
+ ),
167
+ ],
168
if (this.options.contains(AddressTextFieldOption.addressBook)) ...[
169
+ SizedBox(width: 5),
170
Container(
168
- width: prefixIconWidth,
169
- height: prefixIconHeight,
170
- padding: EdgeInsets.only(top: 0),
171
- child: Semantics(
172
- label: S.of(context).address_book,
173
- child: InkWell(
174
- onTap: () async => _presetAddressBookPicker(context),
175
- child: Container(
176
- padding: EdgeInsets.all(8),
177
- decoration: BoxDecoration(
178
- color: buttonColor ??
179
- Theme.of(context).dialogTheme.backgroundColor,
180
- borderRadius: BorderRadius.all(Radius.circular(6))),
181
- child: Image.asset(
182
- 'assets/images/open_book.png',
183
- color: iconColor ??
184
- Theme.of(context)
185
- .extension<SendPageTheme>()!
186
- .textFieldButtonIconColor,
187
- )),
188
- ),
189
- ))
190
- ]
171
+ width: prefixIconWidth,
172
+ height: prefixIconHeight,
173
+ padding: EdgeInsets.only(top: 0),
174
+ child: Semantics(
175
+ label: S.of(context).address_book,
176
+ child: InkWell(
177
+ onTap: () async => _presetAddressBookPicker(context),
178
+ child: Container(
179
+ padding: EdgeInsets.all(8),
180
+ decoration: BoxDecoration(
181
+ color:
182
+ buttonColor ?? Theme.of(context).dialogTheme.backgroundColor,
183
+ borderRadius: BorderRadius.all(Radius.circular(6))),
184
+ child: Image.asset(
185
+ 'assets/images/open_book.png',
186
+ color: iconColor ??
187
+ Theme.of(context)
188
+ .extension<SendPageTheme>()!
189
+ .textFieldButtonIconColor,
190
+ )),
191
+ ),
192
+ ),
193
+ ),
194
+ ],
195
+ if (this.options.contains(AddressTextFieldOption.walletAddresses)) ...[
196
+ SizedBox(width: 5),
197
+ Container(
198
+ width: prefixIconWidth,
199
+ height: prefixIconHeight,
200
+ padding: EdgeInsets.only(top: 0),
201
+ child: Semantics(
202
+ label: S.of(context).address_book,
203
+ child: InkWell(
204
+ onTap: () async => _presetWalletAddressPicker(context),
205
+ child: Container(
206
+ padding: EdgeInsets.all(8),
207
+ decoration: BoxDecoration(
208
+ color:
209
+ buttonColor ?? Theme.of(context).dialogTheme.backgroundColor,
210
+ borderRadius: BorderRadius.all(Radius.circular(6))),
211
+ child: Image.asset(
212
+ 'assets/images/open_book.png',
213
+ color: iconColor ??
214
+ Theme.of(context)
215
+ .extension<SendPageTheme>()!
216
+ .textFieldButtonIconColor,
217
+ )),
218
+ ),
219
+ ),
220
+ )
221
+ ],
222
],
223
),
224
))
228
229
Future<void> _presentQRScanner(BuildContext context) async {
230
bool isCameraPermissionGranted =
200
- await PermissionHandler.checkPermission(Permission.camera, context);
231
+ await PermissionHandler.checkPermission(Permission.camera, context);
232
if (!isCameraPermissionGranted) return;
233
final code = await presentQRScanner();
234
if (code.isEmpty) {
255
}
256
}
257
258
+ Future<void> _presetWalletAddressPicker(BuildContext context) async {
259
+ final address = await Navigator.of(context).pushNamed(Routes.pickerWalletAddress);
260
+
261
+ if (address is String) {
262
+ controller?.text = address;
263
+ onPushAddressPickerButton?.call(context);
264
+ }
265
+ }
266
+
267
Future<void> _pasteAddress(BuildContext context) async {
268
final clipboard = await Clipboard.getData('text/plain');
269
final address = clipboard?.text ?? '';