listProjects method
Lists all Firebase projects associated with the currently authenticated account and returns their IDs.
Implementation
Future<List<String>> listProjects() async {
// 1. Show the pretty table to the user (as requested)
await run('firebase', ['projects:list']);
// 2. Fetch JSON silently for programmatic parsing
try {
final result = await runWithResult(
'firebase',
['projects:list', '--json'],
silent: true,
);
final decoded = jsonDecode(result.stdout.toString()) as Map<String, dynamic>;
final projects = <String>[];
if (decoded.containsKey('result')) {
final list = decoded['result'] as List<dynamic>;
for (var p in list) {
if (p is Map && p.containsKey('projectId')) {
projects.add(p['projectId'] as String);
}
}
}
return projects;
} catch (e) {
print('⚠️ Failed to fetch projects as JSON for internal validation.');
return [];
}
}