Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup different firebase environments in Flutter

Tags:

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.

like image 908
Daniel Brotherston Avatar asked May 15 '18 19:05

Daniel Brotherston


People also ask

Can you have multiple Firebase projects?

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.

How do you set up flavors in Flutter?

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..

Is Flutter Firebase full stack?

Flutter and Firebase can work well together to create a full stack app.


Video Answer


1 Answers

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) 
like image 167
Oliver Dixon Avatar answered Oct 01 '22 05:10

Oliver Dixon