FormScopedWidget constructor

const FormScopedWidget({
  1. Key? key,
})

Abstract class to implement the View portion of the form widget used to both add new and edit existing forms.

The FormRef including the function of the WidgetRef and form information is passed to build, and the View is implemented using it.

Implement FormAddPageScopedWidget and FormEditPageScopedWidget together as follows.

新規追加と既存の編集を両立させるために利用するフォームウィジェットのView部分を実装するための抽象クラス。

buildWidgetRefの機能とフォームの情報を含めたFormRefが渡されるのでそれを用いてViewを実装します。

FormAddPageScopedWidgetFormEditPageScopedWidgetを合わせて下記のように実装します。

@immutable
@PagePath("user/add")
class UserAddPage extends FormAddPageScopedWidget {
  const UserAddPage({
    super.key,
  });

  @pageRouteQuery
  static const query = _$UserAddPageQuery();

  @override
  FormScopedWidget build(BuildContext context, PageRef ref) =>
    const UserForm();
}

@immutable
@PagePath("user/{edit_id}/edit")
class UserEditPage extends FormEditPageScopedWidget {
  const UserEditPage({
    super.key,
    @PageParam("edit_id") required super.editId,
  });

  @pageRouteQuery
  static const query = _$UserEditPageQuery();

  @override
  FormScopedWidget build(BuildContext context, PageRef ref) =>
    const UserForm();
}

@immutable
class UserForm extends FormScopedWidget {
  const UserForm({super.key});

  @override
  Widget build(BuildContext context, FormRef ref) {
    return Scaffold(
      // Any view form
    );
  }
}

Implementation

const FormScopedWidget({super.key});