initNamedApp function

void initNamedApp({
  1. required String name,
  2. required String appId,
  3. required String apiKey,
  4. required String projectId,
  5. String? databaseUrl,
  6. String? storageBucket,
})

Creates a second app under name, beside the default one.

A product runs on it when given the name: initAuth(app: name), and the same app: on each call after it. The Database needs no init of its own, only a databaseUrl here. Remote Config and App Check run on the default app only.

No Database keeps a disk cache, the default app's included: the SDK names the cache for the database host alone, and two Databases on one host cannot share it.

Throws StateError when the name is already taken.

Implementation

void initNamedApp({
  required String name,
  required String appId,
  required String apiKey,
  required String projectId,
  String? databaseUrl,
  String? storageBucket,
}) {
  if (name.isEmpty) throw ArgumentError.value(name, 'name', 'is empty');
  if (!hasFirebase) {
    throw StateError(
      'this build has no Firebase SDK — configure with FDB_WITH_FIREBASE=ON '
      'and an SDK on CMAKE_PREFIX_PATH (or an emb augment)',
    );
  }
  _createApp(name, appId, apiKey, projectId, databaseUrl, storageBucket);
}