enumeratedWithField<T extends Enum, TField extends FormField<T>> method

void enumeratedWithField<T extends Enum, TField extends FormField<T>>({
  1. required String name,
  2. T? initialValue,
  3. PropertyValueTraits? valueTraits,
  4. required Iterable<T> enumValues,
})

Defines a new property with enum type T for both of property value type and form field value type, and preferred form field type TField.

Note that name must be unique, and validators are registered as factories instead of normal closures (function objects) because some validation framework requires live BuildContext to initialize validator, and current Locale of the application should be stored to BuildContext.

TField affects FormFieldFactory generation by form_companion_generator.

Use values static property of T for enumValues parameter like Brightness.values.

Implementation

void enumeratedWithField<T extends Enum, TField extends FormField<T>>({
  required String name,
  T? initialValue,
  PropertyValueTraits? valueTraits,
  required Iterable<T> enumValues,
}) =>
    addWithField<T, T, TField>(
      name: name,
      initialValue: initialValue,
      valueTraits: valueTraits,
      restorableValueFactory: enumRestorableValueFactory(enumValues),
    );