Skip to content

Commit 89a6274

Browse files
committed
Fix bug where CountryPicker still works in readOnly. Closes #413
1 parent 8c976a2 commit 89a6274

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

lib/src/fields/form_builder_country_picker.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
100100
},
101101
builder: (FormFieldState<Country> field) {
102102
return GestureDetector(
103-
onTap: () {
104-
FocusScope.of(context).requestFocus(FocusNode());
105-
if (widget.isCupertinoPicker) {
106-
_openCupertinoCountryPicker(field);
107-
} else {
108-
_openCountryPickerDialog(field);
109-
}
110-
},
103+
onTap: _readOnly
104+
? null
105+
: () {
106+
FocusScope.of(context).requestFocus(FocusNode());
107+
if (widget.isCupertinoPicker) {
108+
_openCupertinoCountryPicker(field);
109+
} else {
110+
_openCountryPickerDialog(field);
111+
}
112+
},
111113
child: InputDecorator(
112114
decoration: widget.decoration.copyWith(
113115
errorText: field.errorText,
@@ -116,14 +118,9 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
116118
key: ObjectKey(field.value),
117119
children: [
118120
CountryPickerUtils.getDefaultFlagImage(field.value),
119-
SizedBox(
120-
width: 10,
121-
),
121+
SizedBox(width: 10),
122122
Expanded(
123-
child: Text(
124-
field.value?.name ?? '',
125-
style: widget.style,
126-
),
123+
child: Text(field.value?.name ?? '', style: widget.style),
127124
),
128125
],
129126
),
@@ -192,8 +189,8 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
192189
child: ListTile(
193190
contentPadding: EdgeInsets.zero,
194191
leading: CountryPickerUtils.getDefaultFlagImage(country),
195-
title: Text(country.name),
196-
// visualDensity: VisualDensity.compact, //TODO: Re-enable after Flutter 1.17
192+
title: Text('${country.name}'),
193+
visualDensity: VisualDensity.compact,
197194
),
198195
);
199196
}

0 commit comments

Comments
 (0)