Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter web flavor

I have a Flutter web app that uses firebase and I have two firebase projects(dev and prod). I'll like to set up Flavors for this project(just web no mobile).

In mobile, I can use different GoogleService-Info.plist or google-services.json files for either flavor but I could not find anyway to do this on the web app as the configuration is done in the index.html file. Is there any way to do this? Maybe have different HTML files and specify which of them to be bundled while running the app?

Thanks.

like image 210
JideGuru Avatar asked Aug 21 '20 14:08

JideGuru


People also ask

What is a flutter flavor?

flutter build --flavor development. On Android, this determines which product flavor is used during the Gradle build process. On iOS, things can be configured so that a different Xcode scheme is used for each flavor. And as of December 2021, the whole process can be (mostly) automated.

How do you get the flavor in flutter?

If you want to launch a flutter app with a flavor, you have to use the --flavor NAME parameter in the Flutter CLI. To automatically start the app with a flavor in Android Studio we need to change the build configurations: Find main. dart in the Android Studio top toolbar and select Edit Configurations... .

Can you flutter for web?

Yes. Flutter is great for both mobile and web app development as it is highly compatible with current-generation web rendering technologies like HTML, CSS, and JavaScript. Using Flutter, you can easily compile the existing code into a client experience, embed it into the browser, and then deploy it to any web server.


1 Answers

You can use Firebase SDK auto-configuration. By relying on the reserved Hosting URL, you can deploy the same code to multiple Firebase projects.

On each of your Firebase projects, go to Project Overview -> Project settings. See here

Under "Your apps" select your web app. If you haven't, link your web app to a firebase hosting site.

In Firebase SDK snippet, select the automatic option. See here

Replace your current firebase configuration on index.html to:

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="/__/firebase/7.21.0/firebase-app.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="/__/firebase/7.21.0/firebase-analytics.js"></script>

<!-- Initialize Firebase -->
<script src="/__/firebase/init.js"></script>

That's it, this will allow you to use the same index.html for different flavors.

More Info here

like image 137
jpozzi Avatar answered Oct 05 '22 10:10

jpozzi