Solution with shellscript
I currently use one but it is a shell script
Setup your environment-specific index.html
From your project folder create the environment where you will store your index.html files:
mkdir config
cd config
mkdir release
mkdir dev
mkdir uat
Then copy your different index.html (especially the one from web/) to config/release/ config/dev/ and config/uat/
cp ../web/index.html release/ && cp ../web/index.html dev/ && cp ../web/index.html uat/
/!\ MAKE A BACKUP OF YOUR CURRENT FILE LOCATED IN WEB/INDEX.HTML
The script will copy index.html from your different environments directories directly to web/ and erase the current file in web/. I decline any liability should you permanently delete the file. You are warn.
Script file
Create the script file:
touch run.sh && chmod +x run.sh
copy this script inside:
cp config/$1/index.html web/index.html && flutter run -d chrome --no-sound-null-safety
How to use
And run it with either ./run.sh release
, ./run.sh dev
or ./run.sh dev
Use --dart-define for your environment-specific variable
I also run this script along with setting environment variables with --dart-define
flutter run --dart-define=MY_ENV_VARIABLE=ITS_VALUE
NB: I currently disable null-safety because of the libs of my project that are not yet null-safe.