Search code examples
firebaseflutter

Switching between multiple Firebase projects/environments in Flutter?


Has anyone figure out how to switch Firebase project/environments inside the app, say you had a drop down with different dev URLs. We are not talking about different builds, that won't work for us and would require sending multiple versions to TestFlight.

There's a snippet of code we found here.

final options = FirebaseOptions.from({});
final firebaseApp = await FirebaseApp.configure(name: 'some_app_name', options: options);

But we can't figure out how to use it, and don't know if it works correctly.

Edit

It was not officially supported when I wrote this. It now is.


Solution

  • final FirebaseApp app = await FirebaseApp.configure(
        name: 'test',
        options: const FirebaseOptions(
          googleAppID: '1:79601577497:ios:5f2bcc6ba8cecddd',
          gcmSenderID: '79601577497',
          apiKey: 'AIzaSyArgmRGfB5kiQT6CunAOmKRVKEsxKmy6YI-G72PVU',
          projectID: 'flutter-firestore',
        ),
      );
      final Firestore firestore = Firestore(app: app); // this line is imp
    

    Use firebase core package for it to work, https://pub.dev/packages/firebase_core For more info: https://firebase.google.com/docs/projects/multiprojects#node.js