configure method
Configures FlutterFire for the current project using the
provided projectId.
Includes exponential backoff retry logic to handle cases where a newly created project's API hasn't propagated across Google's backend yet.
Implementation
Future<void> configure(String projectId) async {
print('⚙️ Configuring FlutterFire...');
try {
await run('flutterfire', ['--version']);
} catch (e) {
print('❌ FlutterFire CLI not installed');
print('👉 Run: dart pub global activate flutterfire_cli');
rethrow;
}
int retryCount = 0;
const maxRetries = 5;
while (retryCount < maxRetries) {
try {
if (retryCount > 0) {
final delay = retryCount * 5;
print('⏳ Waiting $delay seconds for Firebase project to propagate...');
await Future.delayed(Duration(seconds: delay));
print('🔄 Retrying configuration (Attempt ${retryCount + 1}/$maxRetries)...');
}
await run('flutterfire', [
'configure',
'--project=$projectId',
'--yes',
]);
return; // Success
} catch (e) {
retryCount++;
if (retryCount >= maxRetries) {
print('❌ FlutterFire configuration failed after $maxRetries attempts');
rethrow;
}
}
}
}