Ask Your Question
3

What is the method to connect two Cloud Firestore Projects with a single Flutter application?

asked 2022-03-10 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-07-02 14:00:00 +0000

djk gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-10 11:00:00 +0000

Seen: 14 times

Last updated: Jul 02 '22