generate method

  1. @override
Future<void> generate(
  1. ProjectContext context
)
override

Executes the plugin's code-generation and configuration logic.

Implementation

@override
Future<void> generate(ProjectContext context) async {
  final hexVal = _formatHexToColorVal(context.primaryColor);

  // 1. Create the AppTheme file using our template
  await Services.templateService.renderTemplate(
    templateSubPath: 'styling/cupertino_theme.dart',
    targetPath: '${context.projectPath}/lib/core/theme/app_theme.dart',
    replacements: {
      'PRIMARY_COLOR_VALUE': hexVal,
    },
  );

  // 2. Register styling imports in main.dart
  final currentImports = context.templateReplacements['THEME_IMPORTS'] ?? '';
  context.templateReplacements['THEME_IMPORTS'] = "${currentImports}import 'package:flutter/cupertino.dart';\nimport 'core/theme/app_theme.dart';\n";

  // 3. Update the default MaterialApp configuration to be a CupertinoApp
  if (context.routing != Routing.navigator && !context.useGoRouter && !context.useNavigator) {
    context.templateReplacements['APP_ROUTER_OR_MATERIAL_APP'] = '''
CupertinoApp(
    title: '${context.projectName}',
    theme: AppTheme.theme,
    localizationsDelegates: const [
      DefaultMaterialLocalizations.delegate,
      DefaultWidgetsLocalizations.delegate,
      DefaultCupertinoLocalizations.delegate,
    ],
    home: const CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: Text('Welcome'),
      ),
      child: Center(
        child: Text('Welcome to ${context.projectName}!'),
      ),
    ),
  )''';
  }
}