addDependencies method

Future<void> addDependencies(
  1. String projectDir
)

Implementation

Future<void> addDependencies(String projectDir) async {
  print('📦 Adding dependencies...');

  final pubspecFile = File(path.join(projectDir, 'pubspec.yaml'));
  final pubspecContent = pubspecFile.readAsStringSync();

  final yamlEditor = YamlEditor(pubspecContent);

  // Add dependencies
  final dependencies = {
    'bloc': '^8.1.2',
    'flutter_bloc': '^8.1.3',
    'go_router': '^10.1.2',
    'dartz': '^0.10.1',
    'get_it': '^7.6.0',
    'equatable': '^2.0.5',
  };

  for (final dep in dependencies.entries) {
    try {
      yamlEditor.update(['dependencies', dep.key], dep.value);
    } catch (_) {
      try {
        yamlEditor.appendToList(['dependencies'], {dep.key: dep.value});
      } catch (e) {
        print('Warning: Could not add dependency ${dep.key}: $e');
      }
    }
  }

  // Write modified pubspec back to file
  pubspecFile.writeAsStringSync(yamlEditor.toString());
  print('Dependencies added to pubspec.yaml');
}