recreatePubspec static method

Future<void> recreatePubspec()



Implementation

static Future<void> recreatePubspec() async {
  try {
    final pubspecFile = File('pubspec.yaml');

    // 1 — Delete pubspec.yaml
    if (pubspecFile.existsSync()) {
      pubspecFile.deleteSync();
      print('🗑️ Deleted old pubspec.yaml');
    } else {
      throw FormatException('pubspec.yaml not found');
    }

    // 2 — Run flutter create . -e
    final result = await Process.run('flutter', [
      'create',
      '.',
      '-e',
    ], runInShell: true);

    if (result.exitCode == 0) {
      print('✅ New pubspec.yaml created successfully!');
    } else {
      print('❌ Failed to recreate pubspec.yaml');
      print(result.stderr);
    }
  } on FormatException catch (_) {
    rethrow;
  } catch (e) {
    throw FormatException('❌ Error while recreating pubspec: $e');
  }
}