Skip to content

Commit 579e522

Browse files
committed
prevent firebase from being init twice or blocking launch
1 parent 553e2e2 commit 579e522

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/Backend/firebase.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ Future<List<CosHubPost>> getCosHubPosts(Ref ref) async {
7979
}
8080

8181
//TODO: reset ID when disabled
82+
bool didInitFirebase = false;
8283
Future<void> configurePushNotifications() async {
83-
// Required before doing anything with firebase
84-
await Firebase.initializeApp(
85-
options: DefaultFirebaseOptions.currentPlatform,
86-
);
84+
if (!didInitFirebase) {
85+
// Required before doing anything with firebase
86+
await Firebase.initializeApp(
87+
options: DefaultFirebaseOptions.currentPlatform,
88+
);
89+
didInitFirebase = true;
90+
}
91+
8792
//Disable firebase and clear ID
8893
if (!HiveProxy.getOrDefault(settings, marketingNotificationsEnabled, defaultValue: marketingNotificationsEnabledDefault) ||
8994
HiveProxy.getOrDefault(settings, hasCompletedOnboarding, defaultValue: hasCompletedOnboardingDefault) != hasCompletedOnboardingVersionToAgree) {

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Future<void> main() async {
152152

153153
initFlutter();
154154
await initHive();
155-
await configurePushNotifications();
155+
configurePushNotifications();
156156
initMainApp();
157157
}
158158

0 commit comments

Comments
 (0)