@@ -9,9 +9,10 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
9
9
/// If the [onChanged] callback is null or the list of items is null
10
10
/// then the dropdown button will be disabled, i.e. its arrow will be
11
11
/// displayed in grey and it will not respond to input. A disabled button
12
- /// will display the [disabledHint] widget if it is non-null. If
13
- /// [disabledHint] is also null but [hint] is non-null, [hint] will instead
14
- /// be displayed.
12
+ /// will display the [disabledHint] widget if it is non-null.
13
+ ///
14
+ /// If [decoration.hint] and variations is non-null and [disabledHint] is null,
15
+ /// the [decoration.hint] widget will be displayed instead.
15
16
final List <DropdownMenuItem <T >> items;
16
17
17
18
/// A placeholder widget that is displayed by the dropdown button.
@@ -23,8 +24,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
23
24
24
25
/// A message to show when the dropdown is disabled.
25
26
///
26
- /// Displayed if [items] or [onChanged] is null. If [hint] is non-null and
27
- /// [disabledHint] is null, the [hint] widget will be displayed instead.
27
+ /// Displayed if [items] or [onChanged] is null. If [decoration.hint] and
28
+ /// variations is non-null and [disabledHint] is null, the [decoration.hint]
29
+ /// widget will be displayed instead.
28
30
final Widget ? disabledHint;
29
31
30
32
/// Called when the dropdown button is tapped.
@@ -219,40 +221,42 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
219
221
220
222
/// Defines the corner radii of the menu's rounded rectangle shape.
221
223
///
222
- /// The radii of the first menu item's top left and right corners are
224
+ /// The radius of the first menu item's top left and right corners are
223
225
/// defined by the corresponding properties of the [borderRadius] .
224
226
/// Similarly, the radii of the last menu item's bottom and right corners
225
227
/// are defined by the corresponding properties of the [borderRadius] .
226
228
final BorderRadius ? borderRadius;
227
229
228
230
/// Creates field for Dropdown button
229
231
FormBuilderDropdown ({
230
- Key ? key,
231
- //From Super
232
- required String name,
233
- FormFieldValidator <T >? validator,
234
- T ? initialValue,
235
- InputDecoration decoration = const InputDecoration (),
236
- ValueChanged <T ?>? onChanged,
237
- ValueTransformer <T ?>? valueTransformer,
238
- bool enabled = true ,
239
- FormFieldSetter <T >? onSaved,
240
- AutovalidateMode autovalidateMode = AutovalidateMode .disabled,
241
- VoidCallback ? onReset,
242
- FocusNode ? focusNode,
232
+ super .key,
233
+ required super .name,
234
+ super .validator,
235
+ super .initialValue,
236
+ super .decoration,
237
+ super .onChanged,
238
+ super .valueTransformer,
239
+ super .enabled,
240
+ super .onSaved,
241
+ super .autovalidateMode = AutovalidateMode .disabled,
242
+ super .onReset,
243
+ super .focusNode,
243
244
required this .items,
244
245
this .isExpanded = true ,
245
246
this .isDense = true ,
246
247
this .elevation = 8 ,
247
248
this .iconSize = 24.0 ,
248
- this .hint,
249
+ @Deprecated ('Please use decoration.hint and variations to set your desired label' )
250
+ this .hint,
249
251
this .style,
250
252
this .disabledHint,
251
253
this .icon,
252
254
this .iconDisabledColor,
253
255
this .iconEnabledColor,
254
- this .allowClear = false ,
255
- this .clearIcon = const Icon (Icons .close),
256
+ @Deprecated ('Please use decoration.suffix to set your desired behavior' )
257
+ this .allowClear = false ,
258
+ @Deprecated ('Please use decoration.suffixIcon to set your desired icon' )
259
+ this .clearIcon = const Icon (Icons .close),
256
260
this .onTap,
257
261
this .autofocus = false ,
258
262
this .shouldRequestFocus = false ,
@@ -264,23 +268,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
264
268
this .enableFeedback,
265
269
this .borderRadius,
266
270
this .alignment = AlignmentDirectional .centerStart,
267
- }) : /*: assert(allowClear == true || clearIcon != null)*/ super (
268
- key: key,
269
- initialValue: initialValue,
270
- name: name,
271
- validator: validator,
272
- valueTransformer: valueTransformer,
273
- onChanged: onChanged,
274
- autovalidateMode: autovalidateMode,
275
- onSaved: onSaved,
276
- enabled: enabled,
277
- onReset: onReset,
278
- decoration: decoration,
279
- focusNode: focusNode,
271
+ }) : super (
280
272
builder: (FormFieldState <T ?> field) {
281
273
final state = field as _FormBuilderDropdownState <T >;
282
- // DropdownButtonFormField
283
- // TextFormField
284
274
285
275
void changeValue (T ? value) {
286
276
if (shouldRequestFocus) {
@@ -290,60 +280,42 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
290
280
}
291
281
292
282
return InputDecorator (
293
- decoration: state.decoration.copyWith (
294
- floatingLabelBehavior: hint == null
295
- ? decoration.floatingLabelBehavior
296
- : FloatingLabelBehavior .always,
297
- ),
283
+ decoration: state.decoration,
298
284
isEmpty: state.value == null ,
299
- child: Row (
300
- children: < Widget > [
301
- Expanded (
302
- child: DropdownButtonHideUnderline (
303
- child: DropdownButton <T >(
304
- isExpanded: isExpanded,
305
- hint: hint,
306
- items: items,
307
- value: field.value,
308
- style: style,
309
- isDense: isDense,
310
- disabledHint: field.value != null
311
- ? (items
312
- .firstWhereOrNull ((dropDownItem) =>
313
- dropDownItem.value == field.value)
314
- ? .child ??
315
- Text (field.value.toString ()))
316
- : disabledHint,
317
- elevation: elevation,
318
- iconSize: iconSize,
319
- icon: icon,
320
- iconDisabledColor: iconDisabledColor,
321
- iconEnabledColor: iconEnabledColor,
322
- onChanged: state.enabled
323
- ? (value) => changeValue (value)
324
- : null ,
325
- onTap: onTap,
326
- focusNode: state.effectiveFocusNode,
327
- autofocus: autofocus,
328
- dropdownColor: dropdownColor,
329
- focusColor: focusColor,
330
- itemHeight: itemHeight,
331
- selectedItemBuilder: selectedItemBuilder,
332
- menuMaxHeight: menuMaxHeight,
333
- borderRadius: borderRadius,
334
- enableFeedback: enableFeedback,
335
- alignment: alignment,
336
- ),
337
- ),
338
- ),
339
- if (allowClear && state.enabled && field.value != null ) ...[
340
- const VerticalDivider (),
341
- InkWell (
342
- onTap: () => changeValue (null ),
343
- child: clearIcon,
344
- ),
345
- ]
346
- ],
285
+ child: DropdownButtonHideUnderline (
286
+ child: DropdownButton <T >(
287
+ isExpanded: isExpanded,
288
+ hint: hint,
289
+ items: items,
290
+ value: field.value,
291
+ style: style,
292
+ isDense: isDense,
293
+ disabledHint: field.value != null
294
+ ? (items
295
+ .firstWhereOrNull ((dropDownItem) =>
296
+ dropDownItem.value == field.value)
297
+ ? .child ??
298
+ Text (field.value.toString ()))
299
+ : disabledHint,
300
+ elevation: elevation,
301
+ iconSize: iconSize,
302
+ icon: icon,
303
+ iconDisabledColor: iconDisabledColor,
304
+ iconEnabledColor: iconEnabledColor,
305
+ onChanged:
306
+ state.enabled ? (value) => changeValue (value) : null ,
307
+ onTap: onTap,
308
+ focusNode: state.effectiveFocusNode,
309
+ autofocus: autofocus,
310
+ dropdownColor: dropdownColor,
311
+ focusColor: focusColor,
312
+ itemHeight: itemHeight,
313
+ selectedItemBuilder: selectedItemBuilder,
314
+ menuMaxHeight: menuMaxHeight,
315
+ borderRadius: borderRadius,
316
+ enableFeedback: enableFeedback,
317
+ alignment: alignment,
318
+ ),
347
319
),
348
320
);
349
321
},
0 commit comments