Skip to content

Commit 29a7cf7

Browse files
committed
Show country flag for PhoneField
1 parent 194610b commit 29a7cf7

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

lib/src/fields/form_builder_phone_field.dart

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,9 @@ class FormBuilderPhoneFieldState extends State<FormBuilderPhoneField> {
212212
focusNode: _readOnly ? AlwaysDisabledFocusNode() : widget.focusNode,
213213
decoration: widget.decoration.copyWith(
214214
enabled: !_readOnly,
215-
prefix: GestureDetector(
216-
onTap: () {
217-
FocusScope.of(context).requestFocus(FocusNode());
218-
if (widget.isCupertinoPicker) {
219-
_openCupertinoCountryPicker(field);
220-
} else {
221-
_openCountryPickerDialog(field);
222-
}
223-
},
224-
child: Text(
225-
"+${_selectedDialogCountry.phoneCode} ",
226-
style: widget.style,
227-
),
228-
),
215+
// prefixIcon: widget.decoration.prefixIcon == null ? _textFieldPrefix(field) : widget.decoration.prefixIcon,
216+
// prefix: widget.decoration.prefixIcon != null ? _textFieldPrefix(field) : null,
217+
prefix: _textFieldPrefix(field),
229218
),
230219
// initialValue: "${_initialValue ?? ''}",
231220
maxLines: widget.maxLines,
@@ -260,6 +249,36 @@ class FormBuilderPhoneFieldState extends State<FormBuilderPhoneField> {
260249
);
261250
}
262251

252+
Widget _textFieldPrefix(field){
253+
return GestureDetector(
254+
onTap: () {
255+
FocusScope.of(context).requestFocus(FocusNode());
256+
if (widget.isCupertinoPicker) {
257+
_openCupertinoCountryPicker(field);
258+
} else {
259+
_openCountryPickerDialog(field);
260+
}
261+
},
262+
child: ConstrainedBox(
263+
constraints: BoxConstraints(
264+
minWidth: 100,
265+
maxWidth: 120,
266+
),
267+
child: Row(
268+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
269+
children: <Widget>[
270+
Icon(Icons.arrow_drop_down),
271+
CountryPickerUtils.getDefaultFlagImage(_selectedDialogCountry),
272+
Text(
273+
"+${_selectedDialogCountry.phoneCode} ",
274+
style: widget.style ?? Theme.of(context).textTheme.subhead,
275+
),
276+
],
277+
),
278+
),
279+
);
280+
}
281+
263282
void _openCupertinoCountryPicker(FormFieldState field) {
264283
showCupertinoModalPopup<void>(
265284
context: context,

pubspec.lock

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ packages:
2121
name: archive
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "2.0.11"
24+
version: "2.0.13"
2525
args:
2626
dependency: transitive
2727
description:
2828
name: args
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.5.2"
31+
version: "1.6.0"
3232
async:
3333
dependency: transitive
3434
description:
3535
name: async
3636
url: "https://pub.dartlang.org"
3737
source: hosted
38-
version: "2.4.0"
38+
version: "2.4.1"
3939
boolean_selector:
4040
dependency: transitive
4141
description:
4242
name: boolean_selector
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.0.5"
45+
version: "2.0.0"
4646
charcode:
4747
dependency: transitive
4848
description:
4949
name: charcode
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.1.2"
52+
version: "1.1.3"
5353
collection:
5454
dependency: transitive
5555
description:
5656
name: collection
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "1.14.11"
59+
version: "1.14.12"
6060
convert:
6161
dependency: transitive
6262
description:
@@ -84,7 +84,7 @@ packages:
8484
name: crypto
8585
url: "https://pub.dartlang.org"
8686
source: hosted
87-
version: "2.1.3"
87+
version: "2.1.4"
8888
csslib:
8989
dependency: transitive
9090
description:
@@ -206,7 +206,7 @@ packages:
206206
name: image
207207
url: "https://pub.dartlang.org"
208208
source: hosted
209-
version: "2.1.4"
209+
version: "2.1.12"
210210
image_picker:
211211
dependency: "direct main"
212212
description:
@@ -367,7 +367,7 @@ packages:
367367
name: quiver
368368
url: "https://pub.dartlang.org"
369369
source: hosted
370-
version: "2.0.5"
370+
version: "2.1.3"
371371
rating_bar:
372372
dependency: "direct main"
373373
description:
@@ -421,7 +421,7 @@ packages:
421421
name: source_map_stack_trace
422422
url: "https://pub.dartlang.org"
423423
source: hosted
424-
version: "1.1.5"
424+
version: "2.0.0"
425425
source_maps:
426426
dependency: transitive
427427
description:
@@ -435,7 +435,7 @@ packages:
435435
name: source_span
436436
url: "https://pub.dartlang.org"
437437
source: hosted
438-
version: "1.5.5"
438+
version: "1.7.0"
439439
stack_trace:
440440
dependency: transitive
441441
description:
@@ -470,21 +470,21 @@ packages:
470470
name: test
471471
url: "https://pub.dartlang.org"
472472
source: hosted
473-
version: "1.9.4"
473+
version: "1.14.4"
474474
test_api:
475475
dependency: transitive
476476
description:
477477
name: test_api
478478
url: "https://pub.dartlang.org"
479479
source: hosted
480-
version: "0.2.11"
480+
version: "0.2.15"
481481
test_core:
482482
dependency: transitive
483483
description:
484484
name: test_core
485485
url: "https://pub.dartlang.org"
486486
source: hosted
487-
version: "0.2.15"
487+
version: "0.3.4"
488488
typed_data:
489489
dependency: transitive
490490
description:
@@ -527,13 +527,20 @@ packages:
527527
url: "https://pub.dartlang.org"
528528
source: hosted
529529
version: "1.1.0"
530+
webkit_inspection_protocol:
531+
dependency: transitive
532+
description:
533+
name: webkit_inspection_protocol
534+
url: "https://pub.dartlang.org"
535+
source: hosted
536+
version: "0.7.3"
530537
xml:
531538
dependency: transitive
532539
description:
533540
name: xml
534541
url: "https://pub.dartlang.org"
535542
source: hosted
536-
version: "3.5.0"
543+
version: "3.6.1"
537544
yaml:
538545
dependency: transitive
539546
description:

0 commit comments

Comments
 (0)