Skip to content

Commit

Permalink
fix: Fixed a bug that initialization could not wait when executed at …
Browse files Browse the repository at this point in the history
…the same time.
  • Loading branch information
mathrunet committed Feb 1, 2023
1 parent 6b5a35a commit dd38e9a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/katana_firebase/lib/firebase/firebase_core.dart
Expand Up @@ -34,8 +34,9 @@ class FirebaseCore {
/// Returns `true` if Firebase is initialized.
///
/// Firebaseが初期化されている場合`true`を返します。
static bool get initialized => _initialized;
static bool _initialized = false;
static bool get initialized => _app != null;

static Completer<void>? _completer;

/// Returns the Firebase region.
///
Expand Down Expand Up @@ -81,22 +82,31 @@ class FirebaseCore {
String region = "asia-northeast1",
FirebaseOptions? options,
}) async {
if (_completer != null) {
return _completer?.future;
}
if (initialized) {
return;
}
if (kIsWeb) {
assert(options != null, "For the Web, Options is always required.");
}
_initialized = true;
_completer = Completer();
try {
FirebaseCore.region = region;
_app = await Firebase.initializeApp(options: options);
if (!kIsWeb) {
FirebaseFirestore.instance.settings = const Settings();
}
_completer?.complete();
_completer = null;
} catch (e) {
_initialized = false;
_completer?.completeError(e);
_completer = null;
rethrow;
} finally {
_completer?.complete();
_completer = null;
}
}

Expand Down

0 comments on commit dd38e9a

Please sign in to comment.