79551923

Date: 2025-04-03 03:18:30
Score: 0.5
Natty:
Report link

The issue was caused by Firebase dose not use the same instance in both flutter and swift, and Firestore being accessed from Swift before Flutter had finished initializing it.

Since Firestore locks its settings at first access, calling Firestore.firestore() too early in Swift (before Flutter finishes initialization) caused a fatal crash.

To fix it, I made sure Flutter fully initialized Firebase and triggered a dummy Firestore call before any Swift code touched Firestore. In main.dart, I added:

await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await FirebaseFirestore.instance.collection("initcheck").limit(1).get();

Since my Firestore rules required authentication, I also added:

match /initcheck/{docId} {
  allow read: if request.auth != null;
}

After that, saving data from Swift using the logged-in user worked perfectly.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: tomsan