body method
Defines the actual body code. path
is passed relative to lib
, baseName
is the filename, and className
is the filename converted to Pascal case.
実際の本体コードを定義します。path
にlib
からの相対パス、baseName
にファイル名が渡され、className
にファイル名をパスカルケースに変換した値が渡されます。
Implementation
@override
String body(String path, String baseName, String className) {
return """
/// Page for forms to add data.
@immutable
@PagePath("\${2:$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("\${3:$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});
/// 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, 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.
\${4}
// Describes the structure of the page.
// TODO: Implement the view.
return \${5:UniversalScaffold()};
}
}
""";
}