Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to add multiple Firebase projects to my Flutter project

I would simply like to know how to add multiple Firebase projects to my flutter app, because I have data in two separate projects.

like image 762
randomUser786 Avatar asked Jul 07 '19 11:07

randomUser786


2 Answers

You need to call FirebaseApp.configure() for each project that you want to add. This works the same as FirebaseApp.initializeApp() on other platforms, so you should be able to use their documentation if it's not self explanatory.

like image 57
Doug Stevenson Avatar answered Sep 21 '22 21:09

Doug Stevenson


This code was able to make a connection to the Cloud Firestore:

  Future<Firestore> _connectFirestore() async {
    final FirebaseApp sharedApp = await FirebaseApp.configure(
      name: 'shared-project',
      options: FirebaseOptions(
        apiKey: 'blah-blah',
        googleAppID: 'blah-blah-blah',
        projectID: 'shared-project-id',
      ),
    );
    return Firestore(app: sharedApp);
  }

However, once I lock down the database to require authentication, now I get a PlatformException(Error 7, FIRFirestoreErrorDomain, Missing or insufficient permissions.). I am struggling to ensure that my Cloud Firestore requests are authenticated correctly.

like image 43
AWhitford Avatar answered Sep 23 '22 21:09

AWhitford