I've created a flutter project 'example', and i want to add to firebase projects 'fire1' and 'fire2'. in the normal way adding firebase is by adding google-services.json and GoogleServices-Info.plist for IOS and Android. so how can I add two firebase in one flutter project?
For connecting your Flutter app to a Firebase project, you can use:
flutterfire configure
Which, by default will add lib/firebase_option.dart file
If, for example, you want to integrate two separate firebase projects, one for dev and one for prod, you can make two directories:
lib/firebase/dev
lib/firebase/prod
Then run these separately:
flutterfire configure -p firebase-project-id-dev , -o lib/firebase/dev/firebase_options.dart
flutterfire configure -p firebase-project-id-prod , -o lib/firebase/prod/firebase_options.dart
Answer the upcoming questions for each command and ensure you see Firebase configuration file lib/firebase/prod/firebase_options.dart generated successfully to ensure your firebase_option has been created in the correct directory.
You can find your firebase-project-id in the firebase console: project overview > project setting > General > Project ID
BTW, here is some useful info about flutterfire configure [arguments]:
Usage: flutterfire configure [arguments]
-h, --help Print this usage information.
-p, --project=<aliasOrProjectId> The Firebase project to use for this command.
-e, --account=<email> The Google account to use for authorization.
-o, --out=<filePath> The output file path of the Dart file that will be generated with your Firebase configuration options.
(defaults to "lib/firebase_options.dart")
-i, --ios-bundle-id=<bundleIdentifier> The bundle identifier of your iOS app, e.g. "com.example.app". If no identifier is provided then an attempt will be made to automatically detect it from your "ios" folder (if it exists).
-m, --macos-bundle-id=<bundleIdentifier> The bundle identifier of your macOS app, e.g. "com.example.app". If no identifier is provided then an attempt will be made to automatically detect it from your "macos" folder (if it
exists).
-a, --android-app-id=<applicationId> The application id of your Android app, e.g. "com.example.app". If no identifier is provided, then an attempt will be made to automatically detect it from your "android" folder (if it
exists).
Run "flutterfire help" to see global options.
This article explains the multi-environment in detail for flutter and firebase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With