Reputation: 6787
I am hosting flutter web app on firebase.
How do I pass env (non secret) variables to firebase?
I deploy with firebase deploy
command.
When running flutter locally, I pass env variable as a flag in command line argument:
flutter run --dart-define=envFileName=local.env --web-browser-flag "--disable-web-security"
Upvotes: 6
Views: 1597
Reputation: 51
I just spent all day figuring this out. I was trying to get Github actions working. So the official docs say to use 'source' in your firebase.json file. https://firebase.google.com/docs/hosting/frameworks/flutter What isn't clear is that when you have source in the config, it will build the flutter app when you run
firebase deploy
. That clears out any build parameters you sent in previously, even if you just built with --dart-define
parameters.
The solution is to change your firebase.conf file to something like this:
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"frameworksBackend": {
"region": "us-central1"
},
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}
}
Then build your app
flutter build --dart-define=envFileName=local.env
Then deploy
firebase deploy
Upvotes: 5