Skip to content

Commit bfe71ac

Browse files
committed
Simplified expressions and added const keyword.
1 parent 0da70f5 commit bfe71ac

8 files changed

+20
-27
lines changed

lib/src/fields/form_builder_checkbox_list.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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_country_picker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

lib/src/fields/form_builder_dropdown.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {
141141
if (widget.allowClear &&
142142
!widget.readOnly &&
143143
field.value != null) ...[
144-
VerticalDivider(),
144+
const VerticalDivider(),
145145
InkWell(
146146
child: widget.clearIcon,
147147
onTap: () {

lib/src/fields/form_builder_image_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
131131
child: Column(
132132
crossAxisAlignment: CrossAxisAlignment.start,
133133
children: <Widget>[
134-
SizedBox(
134+
const SizedBox(
135135
height: 8,
136136
),
137137
Container(

lib/src/fields/form_builder_phone_field.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ class FormBuilderPhoneFieldState extends State<FormBuilderPhoneField> {
263263
}
264264
},
265265
child: ConstrainedBox(
266-
constraints: BoxConstraints(
266+
constraints: const BoxConstraints(
267267
minWidth: 100,
268268
maxWidth: 120,
269269
),
270270
child: Row(
271271
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
272272
children: <Widget>[
273-
Icon(Icons.arrow_drop_down),
273+
const Icon(Icons.arrow_drop_down),
274274
CountryPickerUtils.getDefaultFlagImage(_selectedDialogCountry),
275275
Text(
276276
'+${_selectedDialogCountry.phoneCode} ',
@@ -319,7 +319,7 @@ class FormBuilderPhoneFieldState extends State<FormBuilderPhoneField> {
319319
primaryColor: widget.cursorColor ?? Theme.of(context).primaryColor,
320320
),
321321
child: CountryPickerDialog(
322-
titlePadding: widget.titlePadding ?? EdgeInsets.all(8.0),
322+
titlePadding: widget.titlePadding ?? const EdgeInsets.all(8.0),
323323
searchCursorColor:
324324
widget.cursorColor ?? Theme.of(context).primaryColor,
325325
searchInputDecoration:

lib/src/fields/form_builder_radio.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
7979
}
8080

8181
Widget _leading(FormFieldState<dynamic> field, int i) {
82-
if (widget.leadingInput) return _radio(field, i);
83-
return null;
82+
return widget.leadingInput ? _radio(field, i) : null;
8483
}
8584

8685
Widget _trailing(FormFieldState<dynamic> field, int i) {
87-
if (!widget.leadingInput) return _radio(field, i);
88-
return null;
86+
return !widget.leadingInput ? _radio(field, i) : null;
8987
}
9088

9189
@override
@@ -129,7 +127,7 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
129127
widget.onChanged?.call(value);
130128
},
131129
),
132-
Divider(
130+
const Divider(
133131
height: 0.0,
134132
),
135133
]);

lib/src/fields/form_builder_text_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class FormBuilderTextFieldState extends State<FormBuilderTextField> {
114114
if (widget.controller != null) {
115115
_effectiveController = widget.controller;
116116
} else {
117-
_effectiveController.text = "${_initialValue ?? ''}";
117+
_effectiveController.text = _initialValue ?? '';
118118
}
119119

120120
_effectiveController.addListener(() {

lib/src/form_builder_field_option.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ class FormBuilderFieldOption extends StatelessWidget {
1616

1717
@override
1818
Widget build(BuildContext context) {
19-
if (child != null) {
20-
return child;
21-
} else {
22-
// ignore: deprecated_member_use_from_same_package
23-
return Text(label ?? value.toString());
24-
}
19+
// ignore: deprecated_member_use_from_same_package
20+
return child ?? Text(label ?? value.toString());
2521
}
2622
}

0 commit comments

Comments
 (0)