Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This can be achieved by using the Firebase Multi-Project setup, which allows you to connect to multiple Firebase projects in your application.

Here are the steps to connect two Cloud Firestore projects with a single Flutter application:

  1. Create two Firebase projects on the Firebase Console.
  2. Add both projects to your Flutter app by following the instructions in the Firebase SDK Setup guide for Flutter.
  3. In your Flutter app, initialize both Firebase projects in the main function using the FirebaseApp class.
  4. Use the Firestore.instanceFor method to get the Firestore instance for each project. For example:
FirebaseApp app1 = Firebase.app('project1');
Firestore firestore1 = FirebaseFirestore.instanceFor(app: app1);

FirebaseApp app2 = Firebase.app('project2');
Firestore firestore2 = FirebaseFirestore.instanceFor(app: app2);
  1. You can now perform CRUD (Create, Read, Update, Delete) operations on both Firestore instances in your Flutter app.

Note: When using Multi-Project setup, you need to specify the project ID when calling any Firebase service. For example, if you want to authenticate a user with Firebase Authentication, you need to use the following code:

FirebaseAuth auth1 = FirebaseAuth.instanceFor(app: app1);
auth1.signInWithEmailAndPassword(email: email, password: password)

This ensures that the authentication is done on the correct Firebase project.