FormEnumDropdownField<TEnum extends Enum, TValue> constructor
- Key? key,
- FormController<
TValue> ? form, - FormAffixStyle? prefix,
- FormAffixStyle? suffix,
- String? hintText,
- String? labelText,
- String? emptyErrorText,
- FormStyle? style,
- void onChanged(
- TEnum? value
- required FormEnumDropdownFieldPicker<
TEnum> picker, - FocusNode? focusNode,
- bool keepAlive = true,
- Widget? icon,
- bool expanded = false,
- TValue onSaved(
- TEnum value
- String validator(
- TEnum? value
- TEnum? initialValue,
- 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配下に配置、もしくはformにFormControllerを渡します。
formにFormControllerを渡した場合、一緒にonSaved
も渡してください。データの保存はonSaved
の内容が実行されます。
initialValueにFormController.valueから与えられた初期値を入力します。
内容が変更される度onChangedが実行されます。
FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。
emptyErrorTextが指定されている時に限り、文字が入力されていない場合emptyErrorTextがエラーとして表示されます。
それ以外のエラーチェックはvalidator
を指定することで行ないます。
コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。
pickerを指定することでTEnum
の選択方法を設定することが可能です。
enabledがfalse
になると非有効化されます。
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);
},
);