I am using this package to set environment variables in flutter in a .env .
To read the variables I have to have this is my main.dart
Future main() async {
await DotEnv().load('.env');
runApp(MyApp());
}
And then read like this
print(DotEnv().env['VAR_NAME']);
From this question, I can also add variables in the build command like this
flutter run --dart-define=APP_VERSION=0.1.2
And then to read the ones set in the build command, I have to do this
const appVersion = String.fromEnvironment('APP_VERSION', defaultValue: 'development');
Is there please a way that I can read variables set in either the .env file or the build command the same way?
I will have the variables in my .env file for local development, and the in dev and prod environments they will be set via commands. So how can I find a way that works for both cases?
Thank you