Build and Host Flutter Web to GitHub Pages and use of secret keys 🔑 (Part-2)
Let’s see how we can add a secret key to your GitHub Actions Workflow and pass it on to your Flutter Project

Ahoy!đź‘‹ Another day another blog, and today it is on how to set up and add Secret Key to your GitHub Actions Workflow and pass it onto your Flutter project.
If you’re not aware of how to set up Build and Host Flutter Web please read through Part-1 of this blog.
Build and Deploy using a secret key 🔑
Navigate to Repo Settings Tab > Secrets and variables > Actions and then click on New repository secret.

After that, it will ask you to enter a name for the secret key and the secret key itself inside the secret text field. After entering the details click on Add secret and you should find it under the Repository secrets.


After adding the secret key use it in your workflow file like the below code
Now Let’s see how we can use --dart-define
to pass the secret key into your Flutter project
- Create a new dart file, I have named it as
env.dart
and write a service to take input from--dart-define
.
I have defined a variable myKey
and String.fromEnvironment("MY_KEY", defaultValue: '')
is Environment declarations provided by the surrounding system compiling or running the Dart program. Declarations map a string key to a string value.
Here "MY_KEY"
is the name given in the dart define. If name
is not declared in the environment, the result is instead defaultValue
.
2. Use the service in your code given below where I have specified EnvService.myKey
to get and display the Key.

Voilà we are done 🎉, you can now see the key getting passed on from GitHub Secrets to your Flutter project.

The complete Source code is Available here 👇