initialize static method

Firestore initialize(
  1. String projectId, {
  2. bool useApplicationDefaultAuth = false,
  3. String? databaseId,
  4. Emulator? emulator,
})

Implementation

static Firestore initialize(
  String projectId, {
  bool useApplicationDefaultAuth = false,
  String? databaseId,
  Emulator? emulator,
}) {
  if (initialized) {
    throw Exception('Firestore instance was already initialized');
  }
  final RequestAuthenticator? authenticator;
  if (useApplicationDefaultAuth) {
    authenticator = ApplicationDefaultAuthenticator(
      useEmulator: emulator != null,
    ).authenticate;
  } else {
    FirebaseAuth? auth;
    try {
      auth = FirebaseAuth.instance;
    } catch (e) {
      // FirebaseAuth isn't initialized
    }

    authenticator = TokenAuthenticator.from(auth)?.authenticate;
  }
  _instance = Firestore(
    projectId,
    databaseId: databaseId,
    authenticator: authenticator,
    emulator: emulator,
  );
  return _instance!;
}