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 pubspecPath = '${context.projectPath}/pubspec.yaml';

  // 1. Add Dio dependency
  Services.yamlService.addDependency(pubspecPath, 'dio', '^5.4.0');

  // 2. Render DioClient template
  await Services.templateService.renderTemplate(
    templateSubPath: 'networking/dio_client.dart',
    targetPath: '${context.projectPath}/lib/core/network/dio_client.dart',
    replacements: {
      'BASE_URL': context.backendUrl ?? 'https://api.example.com',
    },
  );

  // 3. Render API Endpoints constants file
  await Services.templateService.renderTemplate(
    templateSubPath: 'networking/api_endpoints.dart',
    targetPath: '${context.projectPath}/lib/core/network/api_endpoints.dart',
    replacements: {
      'BASE_URL': context.backendUrl ?? 'https://api.example.com',
    },
  );
}