FormListBuilder<T, TValue> constructor
FormListBuilder<T, TValue> ({
- Key? key,
- FormController<
TValue> ? form, - Widget top(
- BuildContext context,
- FormListBuilderRef<
T, TValue> ref
- Widget bottom(
- BuildContext context,
- FormListBuilderRef<
T, TValue> ref
- FormStyle? style,
- required Widget builder(
- BuildContext context,
- FormListBuilderRef<
T, TValue> ref, - T item,
- int index,
- void onChanged(
- List<
T> value
- List<
- TValue onSaved(
- List<
T> value
- List<
- String? validator(
- List<
T> value
- List<
- bool readOnly = false,
- List<
T> ? initialValue, - bool enabled = true,
- bool keepAlive = true,
A builder that can add and delete forms.
Make builder
return each form.
You can specify top or bottom to place additional buttons on the form.
If form is specified, the timing when onSaved
is executed is before the timing when onSaved
of the form inside builder
is executed, so it is possible to initialize the array.
Set the initial data by specifying initialValue.
フォームの追加削除を行うことができるビルダー。
builder
に各フォームを返すようにしてください。
topやbottomを指定することでフォームの追加ボタンの設置を行うことが可能です。
formを指定した場合、onSaved
が実行されるタイミングがbuilder
の中身のフォームのonSaved
が実行されるタイミングの前になるので、配列の初期化を行ったりが可能です。
initialValueを指定して初期のデータを設定してください。
Implementation
FormListBuilder({
super.key,
this.form,
this.top,
this.bottom,
this.style,
required Widget Function(
BuildContext context,
FormListBuilderRef<T, TValue> ref,
T item,
int index,
) builder,
this.onChanged,
TValue Function(List<T> value)? onSaved,
String? Function(List<T> value)? validator,
this.readOnly = false,
super.initialValue,
super.enabled,
this.keepAlive = true,
}) : _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) {
final res = validator?.call(value ?? []);
if (res == null) {
return null;
}
return res;
},
);