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 """
/// Define a list of navigation for use with ${className}Page.
enum ${className}PageNavigation {
// TODO: Define the type of navigation.
navigation1,
navigation2;
/// The first navigation to display.
// TODO: Specify the initial navigation.
static const ${className}PageNavigation initialNavigation = ${className}PageNavigation.navigation1;
/// Get the label of ${className}PageNavigation.
// TODO: Specify a label for each navigation.
String get label {
switch (this) {
case ${className}PageNavigation.navigation1:
return "Nav1";
case ${className}PageNavigation.navigation2:
return "Nav2";
}
}
/// Get the icon of ${className}PageNavigation.
// TODO: Specify a icon for each navigation.
Widget get icon {
switch (this) {
case ${className}PageNavigation.navigation1:
return const Icon(Icons.home);
case ${className}PageNavigation.navigation2:
return const Icon(Icons.home);
}
}
/// Get the route query of ${className}PageNavigation.
// TODO: Specify a RouteQuery for each navigation.
RouteQuery? get routeQuery {
switch (this) {
case ${className}PageNavigation.navigation1:
return null;
case ${className}PageNavigation.navigation2:
return null;
}
}
}
/// Page widget for $className.
@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.
\${2}
});
// TODO: Set parameters for the page in the form [final String xxx].
\${3}
/// 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();
@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.
final nestedRouter = ref.page.router(
initialQuery: ${className}PageNavigation.initialNavigation.routeQuery,
pages: [],
);
\${4}
// Describes the structure of the page.
// TODO: Implement the view.
return UniversalScaffold(
body: Router.withConfig(config: nestedRouter),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: theme.color.background,
selectedItemColor: theme.color.primary,
unselectedItemColor: theme.color.weak,
type: BottomNavigationBarType.fixed,
currentIndex: nestedRouter.currentQuery?.key<${className}PageNavigation>()?.index ??
${className}PageNavigation.initialNavigation.index,
onTap: (index) {
final routeQuery = ${className}PageNavigation.values[index].routeQuery;
if (routeQuery == null) {
return;
}
nestedRouter.push(routeQuery);
},
items: [
...${className}PageNavigation.values.map((e) {
return BottomNavigationBarItem(
icon: e.icon,
label: e.label,
);
}),
],
),
);
}
}
""";
}