FormFutureField<T extends Object, TValue> constructor
- FormController<
TValue> ? form, - FormStyle? style,
- required FutureOr<
T?> onTap(- T? currentValue
- Widget builder(
- BuildContext context,
- FormFutureFieldRef<
T, TValue> value
- String parseToString(
- T? value
- FormAffixStyle? prefix,
- FormAffixStyle? suffix,
- bool obscureText = false,
- String? hintText,
- bool readOnly = false,
- String? labelText,
- void onChanged(
- T? value
- String? emptyErrorText,
- bool keepAlive = true,
- bool showDropdownIcon = true,
- Widget? dropdownIcon,
- Key? key,
- TValue onSaved(
- T value
- String? validator(
- T? value
- T? initialValue,
- bool enabled = true,
A form that waits for another process to complete and updates the value of the form based on that value.
Use this when moving to another page and updating form values based on values entered on that page, or updating form values based on API responses.
Specifying onTap describes the data acquisition process after a tap.
You can freely change the display by passing a widget with builder
. If builder
is not passed, a TextField will be displayed. In that case, you can use parseToString to convert the value of T
to a string.
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.
When 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.
If enabled is false
, the text is deactivated.
If readOnly is set to true
, the activation is displayed, but the text cannot be changed.
別の処理の完了を待ってその値を元にフォームの値を更新するフォーム。
別のページに遷移してそのページで入力した値を元にフォームの値を更新する場合やAPIのレスポンスを元にフォームの値を更新する場合に使用します。
onTapを指定することでタップした後のデータ取得処理を記述します。
builder
でウィジェットを渡すことで自由に表示を変更できます。builder
が渡されない場合はTextFieldが表示されます。その際parseToStringでT
の値を文字列に変換することが可能です。
FormController.keyを与えたForm配下に配置、もしくはformにFormControllerを渡します。
formにFormControllerを渡した場合、一緒にonSaved
も渡してください。データの保存はonSaved
の内容が実行されます。
initialValueにFormController.valueから与えられた初期値を入力します。
内容が変更される度onChangedが実行されます。
FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。
emptyErrorTextが指定されている時に限り、文字が入力されていない場合emptyErrorTextがエラーとして表示されます。
それ以外のエラーチェックはvalidator
を指定することで行ないます。
コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。
enabledがfalse
になるとテキストが非有効化されます。
readOnlyがtrue
になっている場合は、有効化の表示になりますが、テキストが変更できなくなります。
Implementation
FormFutureField({
this.form,
this.style,
required this.onTap,
Widget Function(
BuildContext context,
FormFutureFieldRef<T, TValue> value,
)? builder,
this.parseToString,
this.prefix,
this.suffix,
this.obscureText = false,
this.hintText,
this.readOnly = false,
this.labelText,
this.onChanged,
this.emptyErrorText,
this.keepAlive = true,
this.showDropdownIcon = true,
this.dropdownIcon,
super.key,
TValue Function(T value)? onSaved,
String? Function(T? value)? validator,
super.initialValue,
super.enabled,
}) : _builder = builder,
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);
},
);