1
+ import 'package:collection/collection.dart' show IterableExtension;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:flutter/widgets.dart' ;
3
4
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
@@ -19,21 +20,21 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
19
20
/// If [value] is null, this widget is displayed as a placeholder for
20
21
/// the dropdown button's value. This widget is also displayed if the button
21
22
/// is disabled ([items] or [onChanged] is null) and [disabledHint] is null.
22
- final Widget hint;
23
+ final Widget ? hint;
23
24
24
25
/// A message to show when the dropdown is disabled.
25
26
///
26
27
/// Displayed if [items] or [onChanged] is null. If [hint] is non-null and
27
28
/// [disabledHint] is null, the [hint] widget will be displayed instead.
28
- final Widget disabledHint;
29
+ final Widget ? disabledHint;
29
30
30
31
/// Called when the dropdown button is tapped.
31
32
///
32
33
/// This is distinct from [onChanged] , which is called when the user
33
34
/// selects an item from the dropdown.
34
35
///
35
36
/// The callback will not be invoked if the dropdown button is disabled.
36
- final VoidCallback onTap;
37
+ final VoidCallback ? onTap;
37
38
38
39
/// A builder to customize the dropdown buttons corresponding to the
39
40
/// [DropdownMenuItem] s in [items] .
@@ -49,7 +50,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
49
50
///
50
51
/// If this callback is null, the [DropdownMenuItem] from [items]
51
52
/// that matches [value] will be displayed.
52
- final DropdownButtonBuilder selectedItemBuilder;
53
+ final DropdownButtonBuilder ? selectedItemBuilder;
53
54
54
55
/// The z-coordinate at which to place the menu when open.
55
56
///
@@ -109,28 +110,28 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
109
110
///
110
111
/// Defaults to the [TextTheme.subtitle1] value of the current
111
112
/// [ThemeData.textTheme] of the current [Theme] .
112
- final TextStyle style;
113
+ final TextStyle ? style;
113
114
114
115
/// The widget to use for the drop-down button's icon.
115
116
///
116
117
/// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph.
117
- final Widget icon;
118
+ final Widget ? icon;
118
119
119
120
/// The color of any [Icon] descendant of [icon] if this button is disabled,
120
121
/// i.e. if [onChanged] is null.
121
122
///
122
123
/// Defaults to [Colors.grey.shade400] when the theme's
123
124
/// [ThemeData.brightness] is [Brightness.light] and to
124
125
/// [Colors.white10] when it is [Brightness.dark]
125
- final Color iconDisabledColor;
126
+ final Color ? iconDisabledColor;
126
127
127
128
/// The color of any [Icon] descendant of [icon] if this button is enabled,
128
129
/// i.e. if [onChanged] is defined.
129
130
///
130
131
/// Defaults to [Colors.grey.shade700] when the theme's
131
132
/// [ThemeData.brightness] is [Brightness.light] and to
132
133
/// [Colors.white70] when it is [Brightness.dark]
133
- final Color iconEnabledColor;
134
+ final Color ? iconEnabledColor;
134
135
135
136
/// The size to use for the drop-down button's down arrow icon button.
136
137
///
@@ -166,7 +167,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
166
167
final double itemHeight;
167
168
168
169
/// The color for the button's [Material] when it has the input focus.
169
- final Color focusColor;
170
+ final Color ? focusColor;
170
171
171
172
/// {@macro flutter.widgets.Focus.autofocus}
172
173
final bool autofocus;
@@ -175,27 +176,27 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
175
176
///
176
177
/// If it is not provided, the theme's [ThemeData.canvasColor] will be used
177
178
/// instead.
178
- final Color dropdownColor;
179
+ final Color ? dropdownColor;
179
180
180
181
final bool allowClear;
181
182
final Widget clearIcon;
182
183
183
184
/// Creates field for Dropdown button
184
185
FormBuilderDropdown ({
185
- Key key,
186
+ Key ? key,
186
187
//From Super
187
- @ required String name,
188
- FormFieldValidator <T > validator,
189
- T initialValue,
188
+ required String name,
189
+ FormFieldValidator <T >? validator,
190
+ T ? initialValue,
190
191
InputDecoration decoration = const InputDecoration (),
191
- ValueChanged <T > onChanged,
192
- ValueTransformer <T > valueTransformer,
192
+ ValueChanged <T >? onChanged,
193
+ ValueTransformer <T >? valueTransformer,
193
194
bool enabled = true ,
194
- FormFieldSetter <T > onSaved,
195
+ FormFieldSetter <T >? onSaved,
195
196
AutovalidateMode autovalidateMode = AutovalidateMode .disabled,
196
- VoidCallback onReset,
197
- FocusNode focusNode,
198
- @ required this .items,
197
+ VoidCallback ? onReset,
198
+ FocusNode ? focusNode,
199
+ required this .items,
199
200
this .isExpanded = true ,
200
201
this .isDense = true ,
201
202
this .elevation = 8 ,
@@ -227,12 +228,12 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
227
228
onReset: onReset,
228
229
decoration: decoration,
229
230
focusNode: focusNode,
230
- builder: (FormFieldState <T > field) {
231
+ builder: (FormFieldState <T ? > field) {
231
232
final state = field as _FormBuilderDropdownState <T >;
232
233
// DropdownButtonFormField
233
234
// TextFormField
234
235
235
- void changeValue (T value) {
236
+ void changeValue (T ? value) {
236
237
state.requestFocus ();
237
238
state.didChange (value);
238
239
}
@@ -257,9 +258,8 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
257
258
isDense: isDense,
258
259
disabledHint: field.value != null
259
260
? (items
260
- .firstWhere (
261
- (val) => val.value == field.value,
262
- orElse: () => null )
261
+ .firstWhereOrNull (
262
+ (val) => val.value == field.value)
263
263
? .child ??
264
264
Text (field.value.toString ()))
265
265
: disabledHint,
0 commit comments