Use --dart-define=
and --dart-define-from-file=
to resolve this.
Flutter requires the variables during build and not runtime. Either add .env
file to assets and use dotenv library or use the above mentioned to define variables during flutter build web --dart-define-from-file=env.json
.