I have a project done with flutter and i am using firebase for firestore database.
I need to use it in dart side like swift side as well.
but when i run my app and I start using it I am getting an error and the app get crashed.
this is the error :
Terminating app due to uncaught exception ‘FIRIllegalStateException’, reason: ‘Firestore instance has already been started and its settings can no longer be changed. You can only set settings before calling any other methods on a Firestore instance.
terminating due to uncaught exception of type NSException
I really understand the reason cause it is really clear , but I am unable to identify where is the app trying to start and set new settings.
I initialized the firebase app on dart side on my main.dart file inside the initApp method like this:
.....
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
......
and the app does not get crashed when I open it, it crashs specially on a specific part of the code on dart side(I have to find it manually cause even the all exceptions checked in android studio was not able to find it) when I remove the code I have that sends data to firebase database it works fine, this is the code :
.....
DocumentReference<Map<String, dynamic>> documentParent = FirebaseFirestore
.instance
.collection('errors_backend')
.doc(userId == null || userId.isEmpty
? DateTime.now().toIso8601String()
: userId);
.....
now on swift side i actually dont have much code about firebase, i have a file called LocationManager that is an extension of AppDelegate and inside this i have a method that is called every time the location update:
....
import FirebaseFirestore
import Firebase
enum MyError: Error {
case userIDNotFound
}
extension AppDelegate: CLLocationManagerDelegate {
......
....
func sendDataToFirebase(data: [String: String] ) throws {
let db = Firestore.firestore()
......
}
and that it is on swift side i dont have more code about firebase and you can see every time the method is called i call the firestore method.
now like dart side , if i leave the code that is on dart side and i dont call the method that send data to firebase on swift side , the app works fine (but obviusly the app would not send data to firebase database).
so now i am not sure what to do.
on my Podfile i have added this:
pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-
frameworks.git', :tag => '10.16.0'
i have tried wrapping the code in a try-catch on both side swift and dart but the app is still getting the crash.
i hope some of you guys can help me.
thanks so much.




