Skip to content

Commit eb7c25d

Browse files
committed
Null safety seems to be ok
1 parent d6972e3 commit eb7c25d

22 files changed

+490
-494
lines changed

example/pubspec.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ name: example
22
description: A flutter_form_builder example project.
33

44
environment:
5-
sdk: ">=2.10.0 <3.0.0"
6-
flutter: ">=1.22.0"
5+
sdk: ">=2.12.0 <3.0.0"
76

87
dependencies:
98
flutter:
@@ -22,7 +21,6 @@ dependency_overrides:
2221
dev_dependencies:
2322
flutter_test:
2423
sdk: flutter
25-
intl_translation:
2624

2725
flutter:
2826
uses-material-design: true

lib/l10n/messages_all.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Map<String, LibraryLoader> _deferredLibraries = {
3636
'sk': () => new Future.value(null),
3737
};
3838

39-
MessageLookupByLibrary _findExact(String localeName) {
39+
MessageLookupByLibrary? _findExact(String localeName) {
4040
switch (localeName) {
4141
case 'en':
4242
return messages_en.messages;
@@ -83,7 +83,7 @@ bool _messagesExistFor(String locale) {
8383
}
8484
}
8585

86-
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
86+
MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
8787
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
8888
onFailure: (_) => null);
8989
if (actualLocale == null) return null;

lib/localization/form_builder_localizations.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class FormBuilderLocalizations {
4141
String equalErrorText<T>(T value) => Intl.message(
4242
'This field value must be equal to $value.',
4343
name: 'equalErrorText',
44-
args: [value],
44+
args: [value!],
4545
desc: 'Error Text for equal validator',
4646
);
4747

4848
String notEqualErrorText<T>(T value) => Intl.message(
4949
'This field value must not be equal to $value.',
5050
name: 'notEqualErrorText',
51-
args: [value],
51+
args: [value!],
5252
desc: 'Error Text for not-equal validator',
5353
);
5454

lib/src/fields/form_builder_checkbox.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
1313
/// Additional content displayed below the title.
1414
///
1515
/// Typically a [Text] widget.
16-
final Widget subtitle;
16+
final Widget? subtitle;
1717

1818
/// A widget to display on the opposite side of the tile from the checkbox.
1919
///
2020
/// Typically an [Icon] widget.
21-
final Widget secondary;
21+
final Widget? secondary;
2222

2323
/// The color to use when this checkbox is checked.
2424
///
2525
/// Defaults to accent color of the current [Theme].
26-
final Color activeColor;
26+
final Color? activeColor;
2727

2828
/// The color to use for the check icon when this checkbox is checked.
2929
///
3030
/// Defaults to Color(0xFFFFFFFF).
31-
final Color checkColor;
31+
final Color? checkColor;
3232

3333
/// Where to place the control relative to its label.
3434
final ListTileControlAffinity controlAffinity;
@@ -68,19 +68,19 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
6868
/// Creates a single Checkbox field
6969
FormBuilderCheckbox({
7070
//From Super
71-
Key key,
72-
@required String name,
73-
FormFieldValidator<bool> validator,
74-
bool initialValue,
71+
Key? key,
72+
required String name,
73+
FormFieldValidator<bool>? validator,
74+
bool? initialValue,
7575
InputDecoration decoration = const InputDecoration(),
76-
ValueChanged<bool> onChanged,
77-
ValueTransformer<bool> valueTransformer,
76+
ValueChanged<bool>? onChanged,
77+
ValueTransformer<bool>? valueTransformer,
7878
bool enabled = true,
79-
FormFieldSetter<bool> onSaved,
79+
FormFieldSetter<bool>? onSaved,
8080
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
81-
VoidCallback onReset,
82-
FocusNode focusNode,
83-
@required this.title,
81+
VoidCallback? onReset,
82+
FocusNode? focusNode,
83+
required this.title,
8484
this.activeColor,
8585
this.checkColor,
8686
this.subtitle,
@@ -103,7 +103,7 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
103103
onReset: onReset,
104104
decoration: decoration,
105105
focusNode: focusNode,
106-
builder: (FormFieldState<bool> field) {
106+
builder: (FormFieldState<bool?> field) {
107107
final state = field as _FormBuilderCheckboxState;
108108

109109
return InputDecorator(

lib/src/fields/form_builder_checkbox_group.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,41 @@ import 'package:flutter_form_builder/src/widgets/grouped_checkbox.dart';
66
/// A list of Checkboxes for selecting multiple options
77
class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
88
final List<FormBuilderFieldOption<T>> options;
9-
final Color activeColor;
10-
final Color checkColor;
11-
final Color focusColor;
12-
final Color hoverColor;
13-
final List<T> disabled;
14-
final MaterialTapTargetSize materialTapTargetSize;
9+
final Color? activeColor;
10+
final Color? checkColor;
11+
final Color? focusColor;
12+
final Color? hoverColor;
13+
final List<T>? disabled;
14+
final MaterialTapTargetSize? materialTapTargetSize;
1515
final bool tristate;
1616
final Axis wrapDirection;
1717
final WrapAlignment wrapAlignment;
1818
final double wrapSpacing;
1919
final WrapAlignment wrapRunAlignment;
2020
final double wrapRunSpacing;
2121
final WrapCrossAlignment wrapCrossAxisAlignment;
22-
final TextDirection wrapTextDirection;
22+
final TextDirection? wrapTextDirection;
2323
final VerticalDirection wrapVerticalDirection;
24-
final Widget separator;
24+
final Widget? separator;
2525
final ControlAffinity controlAffinity;
2626
final OptionsOrientation orientation;
2727

2828
/// Creates a list of Checkboxes for selecting multiple options
2929
FormBuilderCheckboxGroup({
30-
Key key,
30+
Key? key,
3131
//From Super
32-
@required String name,
33-
FormFieldValidator<List<T>> validator,
34-
List<T> initialValue,
32+
required String name,
33+
FormFieldValidator<List<T>>? validator,
34+
List<T>? initialValue,
3535
InputDecoration decoration = const InputDecoration(),
36-
ValueChanged<List<T>> onChanged,
37-
ValueTransformer<List<T>> valueTransformer,
36+
ValueChanged<List<T>>? onChanged,
37+
ValueTransformer<List<T>>? valueTransformer,
3838
bool enabled = true,
39-
FormFieldSetter<List<T>> onSaved,
39+
FormFieldSetter<List<T>>? onSaved,
4040
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
41-
VoidCallback onReset,
42-
FocusNode focusNode,
43-
@required this.options,
41+
VoidCallback? onReset,
42+
FocusNode? focusNode,
43+
required this.options,
4444
this.activeColor,
4545
this.checkColor,
4646
this.focusColor,
@@ -72,7 +72,7 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
7272
onReset: onReset,
7373
decoration: decoration,
7474
focusNode: focusNode,
75-
builder: (FormFieldState<List<T>> field) {
75+
builder: (FormFieldState<List<T>?> field) {
7676
final state = field as _FormBuilderCheckboxGroupState<T>;
7777

7878
return InputDecorator(

lib/src/fields/form_builder_dropdown.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:collection/collection.dart' show IterableExtension;
12
import 'package:flutter/material.dart';
23
import 'package:flutter/widgets.dart';
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
@@ -19,21 +20,21 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
1920
/// If [value] is null, this widget is displayed as a placeholder for
2021
/// the dropdown button's value. This widget is also displayed if the button
2122
/// is disabled ([items] or [onChanged] is null) and [disabledHint] is null.
22-
final Widget hint;
23+
final Widget? hint;
2324

2425
/// A message to show when the dropdown is disabled.
2526
///
2627
/// Displayed if [items] or [onChanged] is null. If [hint] is non-null and
2728
/// [disabledHint] is null, the [hint] widget will be displayed instead.
28-
final Widget disabledHint;
29+
final Widget? disabledHint;
2930

3031
/// Called when the dropdown button is tapped.
3132
///
3233
/// This is distinct from [onChanged], which is called when the user
3334
/// selects an item from the dropdown.
3435
///
3536
/// The callback will not be invoked if the dropdown button is disabled.
36-
final VoidCallback onTap;
37+
final VoidCallback? onTap;
3738

3839
/// A builder to customize the dropdown buttons corresponding to the
3940
/// [DropdownMenuItem]s in [items].
@@ -49,7 +50,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
4950
///
5051
/// If this callback is null, the [DropdownMenuItem] from [items]
5152
/// that matches [value] will be displayed.
52-
final DropdownButtonBuilder selectedItemBuilder;
53+
final DropdownButtonBuilder? selectedItemBuilder;
5354

5455
/// The z-coordinate at which to place the menu when open.
5556
///
@@ -109,28 +110,28 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
109110
///
110111
/// Defaults to the [TextTheme.subtitle1] value of the current
111112
/// [ThemeData.textTheme] of the current [Theme].
112-
final TextStyle style;
113+
final TextStyle? style;
113114

114115
/// The widget to use for the drop-down button's icon.
115116
///
116117
/// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph.
117-
final Widget icon;
118+
final Widget? icon;
118119

119120
/// The color of any [Icon] descendant of [icon] if this button is disabled,
120121
/// i.e. if [onChanged] is null.
121122
///
122123
/// Defaults to [Colors.grey.shade400] when the theme's
123124
/// [ThemeData.brightness] is [Brightness.light] and to
124125
/// [Colors.white10] when it is [Brightness.dark]
125-
final Color iconDisabledColor;
126+
final Color? iconDisabledColor;
126127

127128
/// The color of any [Icon] descendant of [icon] if this button is enabled,
128129
/// i.e. if [onChanged] is defined.
129130
///
130131
/// Defaults to [Colors.grey.shade700] when the theme's
131132
/// [ThemeData.brightness] is [Brightness.light] and to
132133
/// [Colors.white70] when it is [Brightness.dark]
133-
final Color iconEnabledColor;
134+
final Color? iconEnabledColor;
134135

135136
/// The size to use for the drop-down button's down arrow icon button.
136137
///
@@ -166,7 +167,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
166167
final double itemHeight;
167168

168169
/// The color for the button's [Material] when it has the input focus.
169-
final Color focusColor;
170+
final Color? focusColor;
170171

171172
/// {@macro flutter.widgets.Focus.autofocus}
172173
final bool autofocus;
@@ -175,27 +176,27 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
175176
///
176177
/// If it is not provided, the theme's [ThemeData.canvasColor] will be used
177178
/// instead.
178-
final Color dropdownColor;
179+
final Color? dropdownColor;
179180

180181
final bool allowClear;
181182
final Widget clearIcon;
182183

183184
/// Creates field for Dropdown button
184185
FormBuilderDropdown({
185-
Key key,
186+
Key? key,
186187
//From Super
187-
@required String name,
188-
FormFieldValidator<T> validator,
189-
T initialValue,
188+
required String name,
189+
FormFieldValidator<T>? validator,
190+
T? initialValue,
190191
InputDecoration decoration = const InputDecoration(),
191-
ValueChanged<T> onChanged,
192-
ValueTransformer<T> valueTransformer,
192+
ValueChanged<T>? onChanged,
193+
ValueTransformer<T>? valueTransformer,
193194
bool enabled = true,
194-
FormFieldSetter<T> onSaved,
195+
FormFieldSetter<T>? onSaved,
195196
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
196-
VoidCallback onReset,
197-
FocusNode focusNode,
198-
@required this.items,
197+
VoidCallback? onReset,
198+
FocusNode? focusNode,
199+
required this.items,
199200
this.isExpanded = true,
200201
this.isDense = true,
201202
this.elevation = 8,
@@ -227,12 +228,12 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
227228
onReset: onReset,
228229
decoration: decoration,
229230
focusNode: focusNode,
230-
builder: (FormFieldState<T> field) {
231+
builder: (FormFieldState<T?> field) {
231232
final state = field as _FormBuilderDropdownState<T>;
232233
// DropdownButtonFormField
233234
// TextFormField
234235

235-
void changeValue(T value) {
236+
void changeValue(T? value) {
236237
state.requestFocus();
237238
state.didChange(value);
238239
}
@@ -257,9 +258,8 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
257258
isDense: isDense,
258259
disabledHint: field.value != null
259260
? (items
260-
.firstWhere(
261-
(val) => val.value == field.value,
262-
orElse: () => null)
261+
.firstWhereOrNull(
262+
(val) => val.value == field.value)
263263
?.child ??
264264
Text(field.value.toString()))
265265
: disabledHint,

0 commit comments

Comments
 (0)