installModule function

Future<void> installModule(
  1. String projectPath,
  2. String module
)

Implementation

Future<void> installModule(String projectPath, String module,) async {

  final flutterCmd = Platform.isWindows ? 'flutter.bat' : 'flutter';


  // ==========================
  // NETWORK MODULE
  // ==========================

  if (module == 'network') {

    await installNetworkModule(projectPath);

    print('🚀 Module "network" added successfully.');
    return; // ⭐ IMPORTANT

  }

  final modules = {
    'ui': 'project_setup',
  };

  final package = modules[module];

  if (package == null) {
    print('❌ Unknown module: $module');
    print('');
    print('Available modules:');
    modules.keys.forEach((m) => print('  $m'));
    return;
  }

  print('📦 Installing $package...');


  await Process.run(
    flutterCmd,
    ['pub', 'add', package],
    workingDirectory: projectPath,
    runInShell: true,
  );

  print('✅ $package installed successfully.');

  // ======================================
  // Generate UI starter example
  // ======================================

  if (module == 'ui') {

    final widgetDir = Directory(
      p.join(projectPath, 'lib', 'presentation', 'widgets'),
    );

    widgetDir.createSync(recursive: true);

    final exampleFile = File(
      p.join(widgetDir.path, 'example_button.dart'),
    );

    if (!exampleFile.existsSync()) {

      exampleFile.writeAsStringSync('''
import 'package:flutter/material.dart';
import 'package:project_setup/project_setup.dart';

class ExampleButton extends StatelessWidget {
  const ExampleButton({super.key});

  @override
  Widget build(BuildContext context) {
    return CustomButton(
      text: "Click Me",
      onTap: () {},
    );
  }
}
''');

      print('🎨 Example UI widget generated.');
    }
  }



  print('🚀 Module "$module" added successfully.');
}