## Notes
It's not listed anywhere in the [Flutter Docs](https://docs.flutter.dev/), but there are two ways to have a Flutter application read environment variables:
- [[#Runtime]]
- [[#From Environment File]]
## Runtime
### Define Constants in Codebase
```dart
```dart
const SOME_VAR = String.fromEnvironment('SOME_VAR', defaultValue: 'SOME_DEFAULT_VALUE');
const OTHER_VAR = String.fromEnvironment('OTHER_VAR', defaultValue: 'OTHER_DEFAULT_VALUE');
```
### Pass Environment Variables in Runtime
```
```bash
flutter run --dart-define=SOME_VAR=SOME_VALUE --dart-define=OTHER_VAR=OTHER_VALUE
```
## From Environment File
Define key-value pairs in a `.env` file
```txt
SOME_VAR=SOME_VALUE
OTHER_VAR=OTHER_VALUE
```
And then run
```bash
flutter run --dart-define-from-file=.env
```
## References
- [Flutter Environment Variables - StackOverflow](https://stackoverflow.com/questions/44250184/setting-environment-variables-in-flutter)
- [[Tech MOC]]