Skip to content

Instantly share code, notes, and snippets.

@caiangums
Created January 19, 2021 18:22
Show Gist options
  • Save caiangums/74047096f1e0d81b8c0c14feb6a5980f to your computer and use it in GitHub Desktop.
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.
#!/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
@michielvaneerd
Copy link

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.

#!/bin/bash

FLUTTER_RUN="flutter run"

if [ ! -z "$1" ]
then
    SUPPLIED_ENV_FILE="$1"
    while IFS= read -r line || [[ -n "$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