migrateApiClient function

Future<void> migrateApiClient(
  1. String projectPath
)

Migrates an existing project's ApiClient to the latest enterprise networking structure used by flutter_enterprise_cli.

This migration ensures compatibility with:

  • Dio based networking
  • Centralized API configuration
  • Interceptor support

Implementation

Future<void> migrateApiClient(String projectPath) async {

  final file = File(
    p.join(projectPath, 'lib/core/network/api_client.dart'),
  );

  if (!file.existsSync()) {
    print("⚠ api_client.dart not found. Skipping.");
    return;
  }

  var content = file.readAsStringSync();


  // Replace old value with new
  content = content.replaceFirst(
    "connectTimeout: const Duration(seconds: 40)",
    "connectTimeout: const Duration(seconds: 30)",
  );


  file.writeAsStringSync(content);

  print("✅ api_client.dart updated successfully.");
}