DropdownButtonFormField<T> constructor

DropdownButtonFormField<T>({Key key, T value, @required List<DropdownMenuItem<T>> items, ValueChanged<T> onChanged, InputDecoration decoration: const InputDecoration(), FormFieldSetter<T> onSaved, FormFieldValidator<T> validator, Widget hint })

Creates a DropdownButton widget wrapped in an InputDecorator and FormField.

The DropdownButton items parameters must not be null.

Implementation

DropdownButtonFormField({
  Key key,
  T value,
  @required List<DropdownMenuItem<T>> items,
  this.onChanged,
  InputDecoration decoration = const InputDecoration(),
  FormFieldSetter<T> onSaved,
  FormFieldValidator<T> validator,
  Widget hint,
}) : assert(decoration != null),
     super(
       key: key,
       onSaved: onSaved,
       initialValue: value,
       validator: validator,
       builder: (FormFieldState<T> field) {
         final InputDecoration effectiveDecoration = decoration
           .applyDefaults(Theme.of(field.context).inputDecorationTheme);
         return InputDecorator(
           decoration: effectiveDecoration.copyWith(errorText: field.errorText),
           isEmpty: value == null,
           child: DropdownButtonHideUnderline(
             child: DropdownButton<T>(
               isDense: true,
               value: value,
               items: items,
               hint: hint,
               onChanged: field.didChange,
             ),
           ),
         );
       }
     );