FormListBuilder<T, TValue> constructor

FormListBuilder<T, TValue>({
  1. Key? key,
  2. FormController<TValue>? form,
  3. Widget top(
    1. BuildContext context,
    2. FormListBuilderRef<T, TValue> ref
    )?,
  4. Widget bottom(
    1. BuildContext context,
    2. FormListBuilderRef<T, TValue> ref
    )?,
  5. FormStyle? style,
  6. required Widget builder(
    1. BuildContext context,
    2. FormListBuilderRef<T, TValue> ref,
    3. T item,
    4. int index,
    ),
  7. void onChanged(
    1. List<T> value
    )?,
  8. TValue onSaved(
    1. List<T> value
    )?,
  9. String? validator(
    1. List<T> value
    )?,
  10. bool readOnly = false,
  11. List<T>? initialValue,
  12. bool enabled = true,
  13. 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に各フォームを返すようにしてください。

topbottomを指定することでフォームの追加ボタンの設置を行うことが可能です。

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;
        },
      );