Skip to content

Commit 589a968

Browse files
committed
Various fixes to resolve flutter analyze issues.
1 parent 26c3307 commit 589a968

13 files changed

+31
-34
lines changed

lib/src/fields/form_builder_checkbox.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class _FormBuilderCheckboxState extends State<FormBuilderCheckbox> {
133133
? null
134134
: () {
135135
FocusScope.of(context).requestFocus(FocusNode());
136-
bool newValue = !(field.value ?? false);
136+
final newValue = !(field.value ?? false);
137137
field.didChange(newValue);
138-
if (widget.onChanged != null) widget.onChanged(newValue);
138+
widget.onChanged?.call(newValue);
139139
},
140140
),
141141
);

lib/src/fields/form_builder_checkbox_list.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
123123
}
124124
},
125125
builder: (FormFieldState<dynamic> field) {
126-
List<Widget> checkboxList = [];
127-
for (int i = 0; i < widget.options.length; i++) {
126+
final checkboxList = <Widget>[];
127+
for (var i = 0; i < widget.options.length; i++) {
128128
checkboxList.addAll([
129129
ListTile(
130130
dense: true,

lib/src/fields/form_builder_color_picker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class _FormBuilderColorPickerState extends State<FormBuilderColorPicker> {
111111
final GlobalKey<FormFieldState> _fieldKey = GlobalKey<FormFieldState>();
112112
FormBuilderState _formState;
113113
Color _initialValue;
114-
FocusNode _focusNode = FocusNode();
114+
final _focusNode = FocusNode();
115115
TextEditingController _textEditingController;
116116

117117
TextEditingController get _effectiveController =>
@@ -226,7 +226,7 @@ class _FormBuilderColorPickerState extends State<FormBuilderColorPicker> {
226226
_effectiveController.text = HexColor(color)?.toHex();
227227
}
228228

229-
_handleFocus() async {
229+
Future<void> _handleFocus() async {
230230
if (effectiveFocusNode.hasFocus && !_readOnly) {
231231
await Future.microtask(
232232
() => FocusScope.of(context).requestFocus(FocusNode()));

lib/src/fields/form_builder_country_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FormBuilderCountryPicker extends StatefulWidget {
3535
Key key,
3636
@required this.attribute,
3737
this.defaultSelectedCountryIsoCode = 'US',
38-
this.initialValue,
38+
@required this.initialValue,
3939
this.validators = const [],
4040
this.readOnly = false,
4141
this.decoration = const InputDecoration(),

lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class FormBuilderDateRangePickerState
243243
);
244244
}
245245

246-
_handleFocus() async {
246+
Future<void> _handleFocus() async {
247247
if (_effectiveFocusNode.hasFocus) {
248248
_hideKeyboard();
249249
var initialFirstDate = value.isEmpty
@@ -252,7 +252,7 @@ class FormBuilderDateRangePickerState
252252
var initialLastDate = value.isEmpty
253253
? (widget.initialLastDate ?? initialFirstDate)
254254
: (value.length < 2 ? initialFirstDate : value[1]);
255-
final List<DateTime> picked = await date_range_picker.showDatePicker(
255+
final picked = await date_range_picker.showDatePicker(
256256
context: context,
257257
initialFirstDate: initialFirstDate,
258258
initialLastDate: initialLastDate,
@@ -269,16 +269,16 @@ class FormBuilderDateRangePickerState
269269
}
270270
}
271271

272-
_valueToText() {
272+
String _valueToText() {
273273
if (value.isEmpty) {
274274
return '';
275275
} else if (value.length == 1) {
276-
return '${format(value[0])}';
276+
return format(value[0]);
277277
}
278278
return '${format(value[0])} - ${format(value[1])}';
279279
}
280280

281-
_setCurrentValue(val) {
281+
void _setCurrentValue(val) {
282282
setState(() {
283283
_currentValue = val ?? [];
284284
});

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
240240
}
241241

242242
// Hack to avoid manual editing of date - as is in DateTimeField library
243-
_handleFocus() async {
243+
Future<void> _handleFocus() async {
244244
setState(() {
245245
stateCurrentValue = _fieldKey.currentState.value;
246246
});

lib/src/fields/form_builder_dropdown.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {
157157
);
158158
}
159159

160-
_changeValue(FormFieldState field, value) {
160+
void _changeValue(FormFieldState field, value) {
161161
FocusScope.of(context).requestFocus(FocusNode());
162162
field.didChange(value);
163-
if (widget.onChanged != null) widget.onChanged(value);
163+
widget.onChanged?.call(value);
164164
}
165165

166166
/*@override

lib/src/fields/form_builder_radio.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
111111
}
112112
},
113113
builder: (FormFieldState<dynamic> field) {
114-
List<Widget> radioList = [];
115-
for (int i = 0; i < widget.options.length; i++) {
114+
final radioList = <Widget>[];
115+
for (var i = 0; i < widget.options.length; i++) {
116116
radioList.addAll([
117117
ListTile(
118118
dense: true,
@@ -124,10 +124,9 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
124124
onTap: _readOnly
125125
? null
126126
: () {
127-
field.didChange(widget.options[i].value);
128-
if (widget.onChanged != null) {
129-
widget.onChanged(widget.options[i].value);
130-
}
127+
final value = widget.options[i].value;
128+
field.didChange(value);
129+
widget.onChanged?.call(value);
131130
},
132131
),
133132
Divider(

lib/src/fields/form_builder_signature_pad.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class _FormBuilderSignaturePadState extends State<FormBuilderSignaturePad> {
8686
super.initState();
8787
}
8888

89-
_getControllerValue() async {
89+
Future<Uint8List> _getControllerValue() async {
9090
return await _effectiveController.toImage() != null
9191
? await _effectiveController.toPngBytes()
9292
: null;

lib/src/fields/form_builder_switch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ class _FormBuilderSwitchState extends State<FormBuilderSwitch> {
168168
? null
169169
: () {
170170
FocusScope.of(context).requestFocus(FocusNode());
171-
bool newValue = !(field.value ?? false);
171+
final newValue = !(field.value ?? false);
172172
field.didChange(newValue);
173-
if (widget.onChanged != null) widget.onChanged(newValue);
173+
widget.onChanged?.call(newValue);
174174
},
175175
),
176176
);

0 commit comments

Comments
 (0)