Skip to content

Commit

Permalink
Update using-environment-variables.md for Flutter (#2687)
Browse files Browse the repository at this point in the history
* Update using-environment-variables.md for Flutter

* Improve using-environment-variables.md

Learning on the go, apparently global variables are unable to be used in the workflow editor

* Improve Changes made

* Improve Changes made

---------

Co-authored-by: Damilola Alimi <alimidammy02@gmail.com>
  • Loading branch information
Code-Remote and dam-ease authored Aug 27, 2024
1 parent fee176d commit fa2d1ca
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions content/yaml-basic-configuration/using-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ defaultConfig {

{{< /tab >}}

{{< tab header="Flutter" >}}
{{<markdown>}}

1. Add your key as an environment variable with the name `MAPS_API_KEY`
2. In the build step, add `--dart-define` to your build script

{{< highlight yaml "style=paraiso-dark">}}
scripts:
- name: Flutter build ipa
script: |
flutter build ipa --release \
--dart-define=MAPS_API_KEY=$MAPS_API_KEY
{{< /highlight >}}

3. Within your Flutter Application, use `String.fromEnvironment` to retrieve these variables in your Dart Code.

{{< highlight Dart "style=paraiso-dark">}}
void main() {
final secret = String.fromEnvironment('MAPS_API_KEY');
print(secret);
}
{{< /highlight >}}
{{</markdown>}}

{{< /tab >}}

{{< tab header="iOS (Swift)" >}}
{{<markdown>}}
1. Add your key as an environment variable with the name `MAPS_API_KEY`
Expand Down Expand Up @@ -144,5 +170,4 @@ GMSServices.provideAPIKey(Bundle.main.object(forInfoDictionaryKey: "MAPS_API_KEY
{{</markdown>}}
{{< /tab >}}

{{< /tabpane >}}

{{< /tabpane >}}

0 comments on commit fa2d1ca

Please sign in to comment.