Created
January 19, 2021 18:22
-
-
Save caiangums/74047096f1e0d81b8c0c14feb6a5980f to your computer and use it in GitHub Desktop.
Flutter CLI still doesn't support passing full environment files, just single values. This script group env vars for passing as `--dart-define=` values.
This file contains 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/bash | |
FLUTTER_RUN="flutter run" | |
if [ ! -z "$1" ] | |
then | |
SUPPLIED_ENV_FILE="$1" | |
while IFS= read -r line | |
do | |
FLUTTER_RUN="$FLUTTER_RUN --dart-define=$line" | |
done < "$SUPPLIED_ENV_FILE" | |
fi | |
source $FLUTTER_RUN | |
# 1. Set env file as: | |
# | |
# KEY=value | |
# | |
# 2. Pass `.env` file as argument and run: | |
# $ ./flutter_run.sh .env |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for your script. I was trying this out on Mac but I saw only the first line of my config file processed. Please see the below change that worked (from https://stackoverflow.com/a/10929511): just added
|| [[ -n "$line" ]]
to the while loop.