initializeAddPackages function

Future<void> initializeAddPackages({
  1. bool updatePackages = true,
})

Implementation

Future<void> initializeAddPackages({bool updatePackages = true}) async {
  Logger.info('📦 Adding packages (resolving latest compatible versions)...');

  // Important Note: These must be executed sequentially, not with Future.wait.
  // Running two 'pub add' commands simultaneously will cause a File Lock error.
  await addDependenciesEfficiently(corePackages, isDev: false);
  await addDependenciesEfficiently(devPackages, isDev: true);

  // The 'pub add' command automatically runs 'pub get', so running it again might be optional.
  // However, it is kept here for finalization and safety if 'updatePackages' is true.
  if (updatePackages) {
    Logger.info("⏳ Finalizing and running pub get...");
    final result = await Process.run('dart', ['pub', 'get'], runInShell: true);

    if (result.exitCode != 0) {
      Logger.warning("⚠️ Warning during pub get:\n${result.stderr}");
    } else {
      Logger.success("✅ Packages finalized successfully.");
    }
  }
}