I am trying to figure out how to set up different firebase environments in a flutter project.
I understand how to do this in firebase, I created two projects, one for production, one for the test. Then, in an iOS or Android project, I could use various methods to switch between these two environments using separate google-services.json
or GoogleServices-Info.plist
files.
In Flutter I found this description of how to separate environments, but it only explains how to differentiate between environments in the flutter code.
How can I get this environment to change what iOS and Android build at compile time? It would even be sufficient simply to allow a file copy hook at build time.
However, when you want to access multiple projects from a single application, you'll need a distinct Firebase application object to reference each one individually. It's up to you to initialize these other instances.
The first step is to download google-services. json file(s) from each Firebase project to a temporary location at your machine. Next, create two folders android/app/src/dev and android/app/src/prod for each flavor. The Firebase configuration files go under their flavor folders under android/app/src/ folder..
Flutter and Firebase can work well together to create a full stack app.
You can switch accounts using FirebaseApp.configure. You can offer your own solution or secret dev panel to switch between them.
The solutions will build flavours and plist implementations will lock you into builds when you deploy for TestFlight + they are messy.
Here's an example: (You could use Assets as well.)
// Load a named file. let filePath = Bundle.main.path(forResource: "MyGoogleService", ofType: "plist") guard let fileopts = FirebaseOptions(contentsOfFile: filePath!) else { assert(false, "Couldn't load config file") } FirebaseApp.configure(options: fileopts)
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