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 """
/// Define a list of tabs for use with ${className}Page.
enum ${className}PageTab {
// TODO: Define the type of tabs.
tab1,
tab2;

/// The first tab to display.
// TODO: Specify the initial tab.
static const ${className}PageTab initialTab = ${className}PageTab.tab1;

/// Get the label of ${className}PageTab.
// TODO: Specify a label for each tab.
String get label {
  switch (this) {
    case ${className}PageTab.tab1:
      return "Tab1";
    case ${className}PageTab.tab2:
      return "Tab2";
  }
}

/// Get the view widget of ${className}PageTab.
// TODO: Specify a widget for each tab.
Widget get view {
  switch (this) {
    case ${className}PageTab.tab1:
      return const Empty();
    case ${className}PageTab.tab2:
      return const Empty();
  }
}
}

/// 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.
  \${4}

  final tabBar = TabBar(
    isScrollable: true,
    indicatorSize: TabBarIndicatorSize.tab,
    tabAlignment: TabAlignment.start,
    tabs: [
      ...${className}PageTab.values.map((e) => Tab(text: e.label)),
    ],
  );
  final tabView = TabBarView(
    children: [
      ...${className}PageTab.values.map((e) => e.view),
    ],
  );

  // Describes the structure of the page.
  // TODO: Implement the view.
  return DefaultTabController(
    initialIndex: ${className}PageTab.initialTab.index,
    length: ${className}PageTab.values.length,
    child: UniversalScaffold(
      appBar: UniversalAppBar(
        bottom: tabBar,
      ),
      body: tabView,
    ),
  );
}
}
""";
}