body method

  1. @override
String body(
  1. String path,
  2. String baseName,
  3. String className
)
override

Defines the actual body code. path is passed relative to lib, baseName is the filename, and className is the filename converted to Pascal case.

実際の本体コードを定義します。pathlibからの相対パス、baseNameにファイル名が渡され、classNameにファイル名をパスカルケースに変換した値が渡されます。

Implementation

@override
String body(String path, String baseName, String className) {
  return """
@immutable
// TODO: Set the path for the page.
@PagePath("\${1:$path}")
class ${className}Page extends PageScopedWidget {
const ${className}Page({
  super.key,
  // TODO: Set parameters for the page.
});

// TODO: Set parameters for the page in the form [final String xxx].

/// Used to transition to the ${className}Page screen.
///
/// ```dart
/// router.push(${className}Page.query(parameters));    // Push page to ${className}Page.
/// router.replace(${className}Page.query(parameters)); // Replace page to ${className}Page.
/// ```
@pageRouteQuery
static const query = _\$${className}PageQuery();

/// Used to transition to the ${className}DetailPage screen.
///
/// ```dart
/// router.push(${className}Form.detailQuery(parameters));    // Push page to ${className}AddPage.
/// router.replace(${className}Form.detailQuery(parameters)); // Push page to ${className}AddPage.
/// ```
static const detailQuery = ${className}DetailPage.query;

/// Used to transition to the ${className}AddPage screen.
///
/// ```dart
/// router.push(${className}Form.addQuery(parameters));    // Push page to ${className}AddPage.
/// router.replace(${className}Form.addQuery(parameters)); // Replace page to ${className}AddPage.
/// ```
static const addQuery = ${className}AddPage.query;

/// Used to transition to the ${className}EditPage screen.
///
/// ```dart
/// router.push(${className}Form.editQuery(parameters));    // Push page to ${className}EditPage.
/// router.replace(${className}Form.editQuery(parameters)); // Replace page to ${className}EditPage.
/// ```
static const editQuery = ${className}EditPage.query;

@override
Widget build(BuildContext context, PageRef ref) {
  // Describes the process of loading
  // and defining variables required for the page.
  // TODO: Implement the variable loading process.
  \${2}

  // Describes the structure of the page.
  // TODO: Implement the view.
  return \${3:UniversalScaffold()};
}
}

@immutable
// TODO: Set the path for the page.
@PagePath("\${4:$path}/:view_id")
class ${className}DetailPage extends PageScopedWidget {
const ${className}DetailPage({
  super.key,
  // TODO: Set parameters for the page.
  @PageParam("view_id") required this.viewId,
});

/// ViewId for Detail.
///
/// Detail用のViewId.
final String viewId;

// TODO: Set parameters for the page in the form [final String xxx].

/// Used to transition to the ${className}DetailPage screen.
///
/// ```dart
/// router.push(${className}DetailPage.query(parameters));    // Push page to ${className}DetailPage.
/// router.replace(${className}DetailPage.query(parameters)); // Replace page to ${className}DetailPage.
/// ```
@pageRouteQuery
static const query = _\$${className}DetailPageQuery();

@override
Widget build(BuildContext context, PageRef ref) {
  // Describes the process of loading
  // and defining variables required for the page.
  // TODO: Implement the variable loading process.
  \${5}

  // Describes the structure of the page.
  // TODO: Implement the view.
  return \${6:UniversalScaffold()};
}
}

/// Page for forms to add data.
@immutable
@PagePath("\${7:$path}/add")
class ${className}AddPage extends FormAddPageScopedWidget {
const ${className}AddPage({
  super.key,
});

/// Used to transition to the ${className}AddPage screen.
///
/// ```dart
/// router.push(${className}AddPage.query(parameters));    // Push page to ${className}AddPage.
/// router.replace(${className}AddPage.query(parameters)); // Replace page to ${className}AddPage.
/// ```
@pageRouteQuery
static const query = _\$${className}AddPageQuery();

@override
FormScopedWidget build(BuildContext context, PageRef ref) =>
    const ${className}Form();
}

/// Page for forms to edit data.
@immutable
@PagePath("\${8:$path}/:edit_id/edit")
class ${className}EditPage extends FormEditPageScopedWidget {
const ${className}EditPage({
  super.key,
  @PageParam("edit_id") required super.editId,
});

/// Used to transition to the ${className}EditPage screen.
///
/// ```dart
/// router.push(${className}EditPage.query(parameters));    // Push page to ${className}EditPage.
/// router.replace(${className}EditPage.query(parameters)); // Replace page to ${className}EditPage.
/// ```
@pageRouteQuery
static const query = _\$${className}EditPageQuery();

@override
FormScopedWidget build(BuildContext context, PageRef ref) =>
    const ${className}Form();
}

/// Widgets for form views.
@immutable
class ${className}Form extends FormScopedWidget {
const ${className}Form({super.key});

@override
Widget build(BuildContext context, FormRef ref) {
  // Describes the process of loading
  // and defining variables required for the page.
  //
  // You can use [ref.isAdding] or [ref.isEditing] to determine if the form is currently adding new data or editing data.
  //
  // If editing is in progress, it is possible to get the ID of the item being edited with [ref.editId].
  // TODO: Implement the variable loading process.
  \${9}

  // Describes the structure of the page.
  // TODO: Implement the view.
  return \${10:UniversalScaffold()};
}
}
""";
}