Skip to content

Commit 4a9d474

Browse files
authored
Enabled strict-inference and enabled stricter type checks. (#549)
* Enabled strict-inference and enabled stricter type checks. * Revised validators to eradicate dynamic types. * Added type safety to equalErrorText message. * Removed dynamic from example since we do not need to draw too much attention to it. * Reverted some excessive typing.
1 parent 0015626 commit 4a9d474

33 files changed

+212
-123
lines changed

analysis_options.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ include: package:pedantic/analysis_options.yaml
33
analyzer:
44
exclude:
55
- lib/l10n/**
6+
7+
language:
8+
strict-inference: true
9+
10+
strong-mode:
11+
implicit-casts: false
12+
implicit-dynamic: false

example/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:pedantic/analysis_options.yaml

example/lib/sources/complete_form.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class CompleteForm extends StatefulWidget {
1414
}
1515

1616
class CompleteFormState extends State<CompleteForm> {
17-
var data;
1817
bool autoValidate = true;
1918
bool readOnly = false;
2019
bool showSegmentedControl = true;
@@ -102,7 +101,7 @@ class CompleteFormState extends State<CompleteForm> {
102101
colorPickerType: ColorPickerType.MaterialPicker,
103102
decoration: const InputDecoration(labelText: 'Pick Color'),
104103
),
105-
FormBuilderChipsInput(
104+
FormBuilderChipsInput<Contact>(
106105
decoration: const InputDecoration(labelText: 'Chips'),
107106
name: 'chips_test',
108107
onChanged: _onChanged,
@@ -258,7 +257,7 @@ class CompleteFormState extends State<CompleteForm> {
258257
keyboardType: TextInputType.number,
259258
textInputAction: TextInputAction.next,
260259
),
261-
FormBuilderDropdown(
260+
FormBuilderDropdown<String>(
262261
// autovalidate: true,
263262
name: 'gender',
264263
decoration: InputDecoration(
@@ -286,7 +285,7 @@ class CompleteFormState extends State<CompleteForm> {
286285
});
287286
},
288287
),
289-
FormBuilderTypeAhead(
288+
FormBuilderTypeAhead<String>(
290289
decoration: const InputDecoration(
291290
labelText: 'Country',
292291
),
@@ -315,7 +314,7 @@ class CompleteFormState extends State<CompleteForm> {
315314
}
316315
},
317316
),
318-
FormBuilderRadioGroup(
317+
FormBuilderRadioGroup<String>(
319318
decoration: const InputDecoration(
320319
labelText: 'My chosen language',
321320
),

lib/localization/form_builder_localizations.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,35 @@ class FormBuilderLocalizations {
3838
);
3939
}
4040

41-
String equalErrorText(value) => Intl.message(
41+
String equalErrorText<T>(T value) => Intl.message(
4242
'This field value must be equal to $value.',
4343
name: 'equalErrorText',
4444
args: [value],
4545
desc: 'Error Text for equal validator',
4646
);
4747

48-
String minErrorText(min) => Intl.message(
48+
String minErrorText(num min) => Intl.message(
4949
'Value must be greater than or equal to $min.',
5050
name: 'minErrorText',
5151
args: [min],
5252
desc: 'Error Text for required field',
5353
);
5454

55-
String minLengthErrorText(minLength) => Intl.message(
55+
String minLengthErrorText(int minLength) => Intl.message(
5656
'Value must have a length greater than or equal to $minLength',
5757
name: 'minLengthErrorText',
5858
args: [minLength],
5959
desc: 'Error Text for minLength validator',
6060
);
6161

62-
String maxErrorText(max) => Intl.message(
62+
String maxErrorText(num max) => Intl.message(
6363
'Value must be less than or equal to $max',
6464
name: 'maxErrorText',
6565
args: [max],
6666
desc: 'Error Text for max validator',
6767
);
6868

69-
String maxLengthErrorText(maxLength) => Intl.message(
69+
String maxLengthErrorText(int maxLength) => Intl.message(
7070
'Value must have a length less than or equal to $maxLength',
7171
name: 'maxLengthErrorText',
7272
args: [maxLength],

lib/src/fields/form_builder_checkbox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
102102
decoration: decoration,
103103
focusNode: focusNode,
104104
builder: (FormFieldState<bool> field) {
105-
final _FormBuilderCheckboxState state = field;
105+
final state = field as _FormBuilderCheckboxState;
106106

107107
return InputDecorator(
108108
decoration: state.decoration(),

lib/src/fields/form_builder_checkbox_group.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
2828
Key key,
2929
//From Super
3030
@required String name,
31-
FormFieldValidator validator,
31+
FormFieldValidator<List<T>> validator,
3232
List<T> initialValue,
3333
InputDecoration decoration = const InputDecoration(),
3434
ValueChanged<List<T>> onChanged,
@@ -71,7 +71,7 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
7171
decoration: decoration,
7272
focusNode: focusNode,
7373
builder: (FormFieldState<List<T>> field) {
74-
final _FormBuilderCheckboxGroupState<T> state = field;
74+
final state = field as _FormBuilderCheckboxGroupState<T>;
7575

7676
return InputDecorator(
7777
decoration: state.decoration(),

lib/src/fields/form_builder_chips_input.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class FormBuilderChipsInput<T> extends FormBuilderField<List<T>> {
6767
decoration: decoration,
6868
focusNode: focusNode,
6969
builder: (FormFieldState<List<T>> field) {
70-
final _FormBuilderChipsInputState<T> state = field;
70+
final state = field as _FormBuilderChipsInputState<T>;
7171

7272
return ChipsInput<T>(
7373
key: ObjectKey(state.value),

lib/src/fields/form_builder_choice_chips.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
288288
decoration: decoration,
289289
focusNode: focusNode,
290290
builder: (FormFieldState<T> field) {
291-
final _FormBuilderChoiceChipState<T> state = field;
291+
final state = field as _FormBuilderChoiceChipState<T>;
292292

293293
return InputDecorator(
294294
decoration: state.decoration(),

lib/src/fields/form_builder_color_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
123123
onReset: onReset,
124124
decoration: decoration,
125125
builder: (FormFieldState<Color> field) {
126-
final _FormBuilderColorPickerFieldState state = field;
126+
final state = field as _FormBuilderColorPickerFieldState;
127127
return TextField(
128128
style: style,
129129
decoration: state.decoration().copyWith(

lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class FormBuilderDateRangePicker extends FormBuilderField<List<DateTime>> {
128128
decoration: decoration,
129129
focusNode: focusNode,
130130
builder: (FormFieldState<List<DateTime>> field) {
131-
final FormBuilderDateRangePickerState state = field;
131+
final state = field as FormBuilderDateRangePickerState;
132132

133133
return TextField(
134134
enabled: enabled,
@@ -258,7 +258,7 @@ class FormBuilderDateRangePickerState
258258
}
259259

260260
@override
261-
void didChange(value) {
261+
void didChange(List<DateTime> value) {
262262
super.didChange(value);
263263
_setTextFieldString();
264264
}

0 commit comments

Comments
 (0)