flutter_feature_generator 2.2.0 copy "flutter_feature_generator: ^2.2.0" to clipboard
flutter_feature_generator: ^2.2.0 copied to clipboard

A powerful code generator with web interface for creating clean architecture features in Flutter projects from OpenAPI/Swagger specifications.

example/example.dart

import 'package:flutter_feature_generator/src/feature_generator.dart';

/// Example of using Flutter Feature Generator programmatically
void main() async {
  // Create a generator instance for your Flutter project
  final generator = FeatureGenerator('/path/to/your/flutter/project');

  // Run the generator
  // This will start the interactive web interface by default
  await generator.run([]);

  // Or run with command-line arguments for non-interactive mode:
  // await generator.run(['user_management', '1,2,3']);
}

/// Example: Generate a feature with specific endpoints
Future<void> generateFeatureExample() async {
  final generator = FeatureGenerator('/path/to/your/flutter/project');

  // Load the swagger specification
  await generator.loadSwaggerSpec();

  // Get available endpoints
  final endpoints = generator.getAvailableEndpoints();

  print('Available endpoints:');
  var allEndpoints = <dynamic>[];
  endpoints.forEach((tag, endpointList) {
    print('Tag: $tag');
    for (final endpoint in endpointList) {
      print('  - ${endpoint.method.toUpperCase()} ${endpoint.path}');
      allEndpoints.add(endpoint);
    }
  });

  // Generate a feature with specific configuration
  // Use the first few endpoints as an example
  final selectedEndpoints = allEndpoints.take(3).toList();
  await generator.generateFeatureWithLayers(
    'user_management', // Feature name in snake_case
    selectedEndpoints, // List of selected endpoints
    {
      'data': true, // Generate data layer
      'domain': true, // Generate domain layer
      'presentation': true, // Generate presentation layer
      'presentationComponents': {
        'bloc': true, // Generate BLoC
        'screens': true, // Generate screens
        'widgets': true, // Generate widgets folder
      }
    },
  );

  print('✅ Feature generated successfully!');
}

/// Example: Setup project dependencies and structure
Future<void> setupProjectExample() async {
  final generator = FeatureGenerator('/path/to/your/flutter/project');

  // Add all required dependencies to pubspec.yaml
  final depResult = await generator.addDependenciesToPubspec();
  if (depResult['success'] == true) {
    print('✅ Dependencies added: ${depResult['added']}');
  }

  // Setup dependency injection structure
  final diResult = await generator.setupDependencyInjection();
  if (diResult['success'] == true) {
    print('✅ DI setup complete');
  }

  // Setup localization
  final l10nResult = await generator.setupLocalization();
  if (l10nResult['success'] == true) {
    print('✅ Localization setup complete');
  }

  // Generate core files
  await generator.generateErrorClass();
  await generator.generateApiConstants();

  print('✅ Project setup complete!');
  print('Run: flutter pub run build_runner build --delete-conflicting-outputs');
}

/// Example: Check project status
Future<void> checkStatusExample() async {
  final generator = FeatureGenerator('/path/to/your/flutter/project');

  // Check if swagger spec is loaded
  final hasSwagger = generator.hasValidSwaggerSpec();
  print('Has valid Swagger: $hasSwagger');

  // Check if core files exist
  final errorExists = generator.coreErrorClassExists();
  final apiConstantsExist = generator.apiConstantsExists();

  print('Core files status:');
  print('  - Error class: ${errorExists ? "✅" : "❌"}');
  print('  - API constants: ${apiConstantsExist ? "✅" : "❌"}');

  // Check DI files
  final diFiles = generator.checkDIFilesExist();
  print('DI files status:');
  print(
      '  - Injection container: ${diFiles['injection_container'] == true ? "✅" : "❌"}');
  print('  - App module: ${diFiles['app_module'] == true ? "✅" : "❌"}');
  print('  - Interceptors: ${diFiles['interceptors'] == true ? "✅" : "❌"}');
}
5
likes
150
points
37
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful code generator with web interface for creating clean architecture features in Flutter projects from OpenAPI/Swagger specifications.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

args, path, shelf, shelf_router

More

Packages that depend on flutter_feature_generator