close method
Closes this app and cleans up all associated resources.
This method:
- Removes the app from the global registry
- Calls
FirebaseService.deleteon all registered services - Closes the HTTP client (if it was created by the SDK)
- Marks the app as deleted
After calling this method, the app instance can no longer be used.
Any subsequent calls to the app or its services will throw a
FirebaseAppException with code 'app-deleted'.
Note: If you provided a custom AppOptions.httpClient, it will NOT be closed automatically. You are responsible for closing it.
Example:
final app = FirebaseApp.initializeApp(options: options);
// Use app...
await app.close();
// App can no longer be used
Implementation
Future<void> close() async {
_checkDestroyed();
// Remove from registry
_defaultAppRegistry.removeApp(name);
// Delete all services
await Future.wait(
_services.values.map((service) {
return service.delete();
}),
);
_services.clear();
// Only close client if it was initialized AND we created it (not user-provided)
if (_httpClient != null && options.httpClient == null) {
(await _httpClient!).close();
}
_isDeleted = true;
}