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 """
/// App Localization.
///
/// ```dart
/// ml().xxx  // Localization for xxx.
/// ```
final ml = AppLocalize();

// TODO: Set the Google Spreadsheet URL for the translation.
@GoogleSpreadSheetLocalize(
[
  "\${6:https://docs.google.com/spreadsheets/d/1bw7IXEr7BGkZ4U6on0OuF7HQkTMgDSm6u5ThpBkDPeo/edit#gid=551986808}",
],
version: 1,
)
class AppLocalize extends _\$AppLocalize {}

/// Define [${className.toPascalCase()}MasamuneAdapter] specific words and settings.
class ${className.toPascalCase()}ModuleOptions extends ModuleOptions {
const ${className.toPascalCase()}ModuleOptions();

// TODO: Define the words used in the module.
}

/// Define [${className.toPascalCase()}MasamuneAdapter] pages.
class ${className.toPascalCase()}ModulePages extends ModulePages {
const ${className.toPascalCase()}ModulePages({
  this.home = const HomePageQuery(),
});

// TODO: Define the pages.
final HomePageQuery home;

@override
List<RouteQueryBuilder> get pages => [
  home,
];
}

/// [AppModuleMasamuneAdapter] should be compiled into a list of [MasamuneAdapters] and passed to [runMasamuneApp.masamuneAdapters].
///
/// ```dart
/// const module = ${className.toPascalCase()}MasamuneAdapter();
///
/// void main() {
///  runMasamuneApp(
///    (adapters) => MasamuneApp(
///      title: title,
///      appRef: appRef,
///      theme: theme,
///      routerConfig: router,
///      localize: l,
///      authAdapter: authAdapter,
///      modelAdapter: modelAdapter,
///      storageAdapter: storageAdapter,
///      functionsAdapter: functionsAdapter,
///      loggerAdapters: loggerAdapters,
///      masamuneAdapters: adapters,
///    ),
///    masamuneAdapters: [module],
///  );
///}
/// ```
@immutable
class ${className.toPascalCase()}MasamuneAdapter extends AppModuleMasamuneAdapter<${className.toPascalCase()}ModulePages, ${className.toPascalCase()}ModuleOptions> {
/// [AppModuleMasamuneAdapter] should be compiled into a list of [MasamuneAdapters] and passed to [runMasamuneApp.masamuneAdapters].
///
/// ```dart
/// const module = ${className.toPascalCase()}MasamuneAdapter();
///
/// void main() {
///  runMasamuneApp(
///    (adapters) => MasamuneApp(
///      title: title,
///      appRef: appRef,
///      theme: theme,
///      routerConfig: router,
///      localize: l,
///      authAdapter: authAdapter,
///      modelAdapter: modelAdapter,
///      storageAdapter: storageAdapter,
///      functionsAdapter: functionsAdapter,
///      loggerAdapters: loggerAdapters,
///      masamuneAdapters: adapters,
///    ),
///    masamuneAdapters: [module],
///  );
///}
///```
const ${className.toPascalCase()}MasamuneAdapter({
  required super.appRef,
  required super.auth,
  required super.router,
  required super.localize,
  required super.theme,
  required super.function,
  super.title,
  super.option = const ${className.toPascalCase()}ModuleOptions(),
  super.page = const ${className.toPascalCase()}ModulePages(),
});

/// You can retrieve the [${className.toPascalCase()}MasamuneAdapter] first given by [MasamuneAdapterScope].
static ${className.toPascalCase()}MasamuneAdapter get primary {
  assert(
    _primary != null,
    "${className.toPascalCase()}MasamuneAdapter is not set. Place [MasamuneAdapterScope] widget closer to the root.",
  );
  return _primary!;
}

static ${className.toPascalCase()}MasamuneAdapter? _primary;

@override
void onInitScope(MasamuneAdapter adapter) {
  super.onInitScope(adapter);
  if (adapter is! ${className.toPascalCase()}MasamuneAdapter) {
    return;
  }
  _primary = adapter;
}

@override
Widget onBuildApp(BuildContext context, Widget app) {
  return MasamuneAdapterScope<${className.toPascalCase()}MasamuneAdapter>(
    adapter: this,
    child: super.onBuildApp(context, app),
  );
}
}
""";
}