Skip to content

Commit 689147a

Browse files
committed
2 parents a8e15d8 + d26d1bc commit 689147a

30 files changed

+77
-690
lines changed

FormBuilder.java

Lines changed: 0 additions & 576 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ This package is dependent on the following packages and plugins:
368368
* [validators](https://pub.dev/packages/validators) by [dart-league](https://github.com/dart-league)
369369
* [signature](https://pub.dev/packages/signature) by [4Q s.r.o.](https://github.com/4Q-s-r-o) with some minor improvements to fit our usage
370370
* [flutter_colorpicker](https://pub.dev/packages/flutter_colorpicker) by [mchome](https://github.com/mchome)
371-
* [flutter_chips_input](https://pub.dev/packages/flutter_chips_input) & [flutter_touch_spin](https://pub.dev/packages/flutter_touch_spin) by [Yours trully :-)](https://github.com/danvick)
371+
* [flutter_chips_input](https://pub.dev/packages/flutter_chips_input) & [flutter_touch_spin](https://pub.dev/packages/flutter_touch_spin) by [Yours truly :-)](https://github.com/danvick)
372372

373373
### RELATED PACKAGES
374374
Here are other field types for `flutter_form_builder`:

lib/src/country_picker_util.dart

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,34 @@ import 'package:country_pickers/countries.dart';
22
import 'package:country_pickers/country.dart';
33

44
class CountryPickerUtil {
5+
static Country _getCountryByField(
6+
String Function(Country) fieldAccessor, String query) {
7+
final queryUpperCase = query.toUpperCase();
8+
return countryList.firstWhere(
9+
(country) => fieldAccessor(country).toUpperCase() == queryUpperCase,
10+
orElse: () => null);
11+
}
12+
513
static Country getCountryByIso3Code(String iso3Code) {
6-
try {
7-
return countryList.firstWhere(
8-
(country) => country.iso3Code.toLowerCase() == iso3Code.toLowerCase(),
9-
);
10-
} catch (error) {
11-
return null;
12-
}
14+
return _getCountryByField((country) => country.iso3Code, iso3Code);
1315
}
1416

1517
static Country getCountryByIsoCode(String isoCode) {
16-
try {
17-
return countryList.firstWhere(
18-
(country) => country.isoCode.toLowerCase() == isoCode.toLowerCase(),
19-
);
20-
} catch (error) {
21-
return null;
22-
}
18+
return _getCountryByField((country) => country.isoCode, isoCode);
2319
}
2420

2521
static Country getCountryByName(String name) {
26-
try {
27-
return countryList.firstWhere(
28-
(country) => country.name.toLowerCase() == name.toLowerCase(),
29-
);
30-
} catch (error) {
31-
return null;
32-
}
22+
return _getCountryByField((country) => country.name, name);
3323
}
3424

3525
static Country getCountryByPhoneCode(String phoneCode) {
36-
try {
37-
return countryList.firstWhere(
38-
(country) => country.phoneCode.toLowerCase() == phoneCode.toLowerCase(),
39-
);
40-
} catch (error) {
41-
return null;
42-
}
26+
return _getCountryByField((country) => country.phoneCode, phoneCode);
4327
}
4428

4529
static Country getCountryByCodeOrName(String codeOrName) {
46-
var country;
47-
country = getCountryByIso3Code(codeOrName);
48-
if (country != null) return country;
49-
country = getCountryByIsoCode(codeOrName);
50-
if (country != null) return country;
51-
country = getCountryByName(codeOrName);
52-
if (country != null) return country;
53-
country = getCountryByPhoneCode(codeOrName);
54-
if (country != null) return country;
55-
return country;
30+
return getCountryByIso3Code(codeOrName) ??
31+
getCountryByIsoCode(codeOrName) ??
32+
getCountryByName(codeOrName) ??
33+
getCountryByPhoneCode(codeOrName);
5634
}
5735
}

lib/src/fields/form_builder_checkbox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class _FormBuilderCheckboxState extends State<FormBuilderCheckbox> {
9696

9797
@override
9898
Widget build(BuildContext context) {
99-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
99+
_readOnly = _formState?.readOnly == true || widget.readOnly;
100100

101101
return FormField(
102102
key: _fieldKey,

lib/src/fields/form_builder_checkbox_list.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
102102

103103
@override
104104
Widget build(BuildContext context) {
105-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
105+
_readOnly = _formState?.readOnly == true || widget.readOnly;
106106

107107
return FormField(
108108
key: _fieldKey,
@@ -136,19 +136,18 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
136136
onTap: _readOnly
137137
? null
138138
: () {
139-
var currentValue = [...field.value];
140-
if (!currentValue.contains(widget.options[i].value)) {
141-
currentValue.add(widget.options[i].value);
139+
final optionValue = widget.options[i].value;
140+
final currentValue = [...field.value];
141+
if (!currentValue.contains(optionValue)) {
142+
currentValue.add(optionValue);
142143
} else {
143-
currentValue.remove(widget.options[i].value);
144+
currentValue.remove(optionValue);
144145
}
145146
field.didChange(currentValue);
146-
if (widget.onChanged != null) {
147-
widget.onChanged(currentValue);
148-
}
147+
widget.onChanged?.call(currentValue);
149148
},
150149
),
151-
Divider(height: 0.0),
150+
const Divider(height: 0.0),
152151
]);
153152
}
154153
return InputDecorator(

lib/src/fields/form_builder_chips_choice.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class _FormBuilderChoiceChipState extends State<FormBuilderChoiceChip> {
9292

9393
@override
9494
Widget build(BuildContext context) {
95-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
95+
_readOnly = _formState?.readOnly == true || widget.readOnly;
9696

9797
return FormField(
9898
key: _fieldKey,
@@ -148,9 +148,7 @@ class _FormBuilderChoiceChipState extends State<FormBuilderChoiceChip> {
148148
FocusScope.of(context).requestFocus(FocusNode());
149149
var choice = selected ? option.value : null;
150150
field.didChange(choice);
151-
if (widget.onChanged != null) {
152-
widget.onChanged(choice);
153-
}
151+
widget.onChanged?.call(choice);
154152
});
155153
},
156154
)

lib/src/fields/form_builder_chips_filter.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class _FormBuilderFilterChipState extends State<FormBuilderFilterChip> {
106106

107107
@override
108108
Widget build(BuildContext context) {
109-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
109+
_readOnly = _formState?.readOnly == true || widget.readOnly;
110110

111111
return FormField(
112112
key: _fieldKey,
@@ -161,9 +161,7 @@ class _FormBuilderFilterChipState extends State<FormBuilderFilterChip> {
161161
}
162162

163163
field.didChange(currentValue);
164-
if (widget.onChanged != null) {
165-
widget.onChanged(currentValue);
166-
}
164+
widget.onChanged?.call(currentValue);
167165
},
168166
);
169167
},

lib/src/fields/form_builder_chips_input.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class _FormBuilderChipsInputState extends State<FormBuilderChipsInput> {
8989

9090
@override
9191
Widget build(BuildContext context) {
92-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
92+
_readOnly = _formState?.readOnly == true || widget.readOnly;
9393

9494
return FormField(
9595
key: _fieldKey,

lib/src/fields/form_builder_color_picker.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,13 @@ class _FormBuilderColorPickerState extends State<FormBuilderColorPicker> {
130130
: null);
131131
_textEditingController =
132132
TextEditingController(text: HexColor(_initialValue)?.toHex());
133-
if (widget.focusNode != null) {
134-
widget.focusNode.addListener(_handleFocus);
135-
}
133+
widget.focusNode?.addListener(_handleFocus);
136134
_focusNode.addListener(_handleFocus);
137135
}
138136

139137
@override
140138
Widget build(BuildContext context) {
141-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
139+
_readOnly = _formState?.readOnly == true || widget.readOnly;
142140

143141
return FormField<Color>(
144142
key: _fieldKey,

lib/src/fields/form_builder_country_picker.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
8080

8181
@override
8282
Widget build(BuildContext context) {
83-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
83+
_readOnly = _formState?.readOnly == true || widget.readOnly;
8484

8585
return FormField<Country>(
8686
key: _fieldKey,
@@ -123,7 +123,7 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
123123
),
124124
Expanded(
125125
child: Text(
126-
"${field.value?.name ?? ''}",
126+
field.value?.name ?? '',
127127
style: widget.style,
128128
),
129129
),
@@ -163,7 +163,7 @@ class _FormBuilderCountryPickerState extends State<FormBuilderCountryPicker> {
163163
primaryColor: widget.cursorColor ?? Theme.of(context).primaryColor,
164164
),
165165
child: CountryPickerDialog(
166-
titlePadding: widget.titlePadding ?? EdgeInsets.all(8.0),
166+
titlePadding: widget.titlePadding ?? const EdgeInsets.all(8.0),
167167
searchCursorColor:
168168
widget.cursorColor ?? Theme.of(context).primaryColor,
169169
searchInputDecoration:

0 commit comments

Comments
 (0)