FormBuilder<T, TValue> constructor

FormBuilder<T, TValue>({
  1. Key? key,
  2. FormController<TValue>? form,
  3. FormStyle? style,
  4. required Widget builder(
    1. BuildContext context,
    2. FormBuilderRef<T, TValue> ref,
    3. T? item
    ),
  5. TValue? onSaved(
    1. T? value
    )?,
  6. T? initialValue,
  7. void onChanged(
    1. T? value
    )?,
  8. FormFieldValidator<T>? validator,
  9. bool enabled = true,
  10. bool keepAlive = true,
})

A builder that can freely change the UI within a form.

Please return the form to builder.

You can change the value of the form by putting a new value in FormBuilderRef.update in builder.

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.

フォームの中のUIを自由に変更することができるビルダー。

builderにフォームを返すようにしてください。

builderの中にあるFormBuilderRef.updateに新しい値を入れることでフォームの値を変更することが可能です。

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

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

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

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

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

Implementation

FormBuilder({
  super.key,
  this.form,
  this.style,
  required Widget Function(
    BuildContext context,
    FormBuilderRef<T, TValue> ref,
    T? item,
  ) builder,
  TValue? Function(T? value)? onSaved,
  super.initialValue,
  this.onChanged,
  super.validator,
  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;
        },
      );