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:
main
function using the FirebaseApp
class.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);
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.