Last active
April 4, 2024 23:33
-
-
Save AhmedAbouelkher/e59cc74c59fd257848aab8d4dc272b51 to your computer and use it in GitHub Desktop.
Create an `env.dart` files passed on the Environment Values passed and prefixed with `flutter_`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # list all system env variables starting with flutter_ and put them in a array variable | |
| values=$(env | grep ^flutter_) | |
| # check if values is empty | |
| if [ -z "$values" ] | |
| then | |
| echo "No environment variables found starting with flutter_" | |
| exit 0 | |
| fi | |
| strippedValues=() | |
| # loop through all values and strip the flutter_ prefix | |
| for value in $values | |
| do | |
| # strip the prefix | |
| key=$(echo $value | sed 's/^flutter_//') | |
| strippedValues+=($key) | |
| done | |
| envString="" | |
| # loop through all values and print them | |
| for envVariable in ${strippedValues[@]} | |
| do | |
| # split the key and value | |
| key=$(echo $envVariable | cut -d '=' -f 1) | |
| value=$(echo $envVariable | cut -d '=' -f 2) | |
| # add the value to the envString | |
| envString+="const $key = \"${value}\";\n" | |
| done | |
| # write the envString to the env.dart file | |
| echo $envString > lib/env.dart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment