FormEnumDropdownField<TEnum extends Enum, TValue> constructor

FormEnumDropdownField<TEnum extends Enum, TValue>({
  1. Key? key,
  2. FormController<TValue>? form,
  3. FormAffixStyle? prefix,
  4. FormAffixStyle? suffix,
  5. String? hintText,
  6. String? labelText,
  7. String? emptyErrorText,
  8. FormStyle? style,
  9. void onChanged(
    1. TEnum? value
    )?,
  10. required FormEnumDropdownFieldPicker<TEnum> picker,
  11. FocusNode? focusNode,
  12. bool keepAlive = true,
  13. Widget? icon,
  14. bool expanded = false,
  15. TValue onSaved(
    1. TEnum value
    )?,
  16. String validator(
    1. TEnum? value
    )?,
  17. TEnum? initialValue,
  18. bool enabled = true,
})

Drop-down form to select from all elements in TEnum.

Place under the Form that gave FormController.key, or pass FormController to form.

When FormController is passed to form, onSaved must also be passed together. The contents of onSaved will be used to save the data.

Enter the initial value given by FormController.value in initialValue.

Each time the content is changed, onChanged is executed.

If FormController.validate is executed, validation and data saving are performed.

Only when emptyErrorText is specified, emptyErrorText will be displayed as an error if no characters are entered.

Other error checking is performed by specifying validator. If a string other than Null is returned in the callback, the string is displayed as an error statement. If Null is returned, it is processed as no error.

By specifying picker, it is possible to set the selection method for TEnum.

Deactivated when enabled is set to false.

TEnumのすべての要素から選択するためのドロップダウンフォーム。

FormController.keyを与えたForm配下に配置、もしくはformFormControllerを渡します。

formFormControllerを渡した場合、一緒にonSavedも渡してください。データの保存はonSavedの内容が実行されます。

initialValueFormController.valueから与えられた初期値を入力します。

内容が変更される度onChangedが実行されます。

FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。

emptyErrorTextが指定されている時に限り、文字が入力されていない場合emptyErrorTextがエラーとして表示されます。

それ以外のエラーチェックはvalidatorを指定することで行ないます。 コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。

pickerを指定することでTEnumの選択方法を設定することが可能です。

enabledfalseになると非有効化されます。

Implementation

FormEnumDropdownField({
  super.key,
  this.form,
  this.prefix,
  this.suffix,
  this.hintText,
  this.labelText,
  this.emptyErrorText,
  this.style,
  this.onChanged,
  required this.picker,
  this.focusNode,
  this.keepAlive = true,
  this.icon,
  this.expanded = false,
  TValue Function(TEnum value)? onSaved,
  String Function(TEnum? value)? validator,
  super.initialValue,
  super.enabled,
})  : assert(
        (form == null && onSaved == null) ||
            (form != null && onSaved != null),
        "Both are required when using [form] or [onSaved].",
      ),
      super(
        builder: (state) {
          return const SizedBox.shrink();
        },
        onSaved: (value) {
          if (value == null) {
            return;
          }
          final res = onSaved?.call(value);
          if (res == null) {
            return;
          }
          form!.value = res;
        },
        validator: (value) {
          if (emptyErrorText.isNotEmpty && value == null) {
            return emptyErrorText;
          }
          return validator?.call(value);
        },
      );