If you are looking for a feature similar to environment variables, this is how you implement them.
In Dart code, defines can be accessed through the following methods:
const someInt = int.fromEnvironment('someInt'); const someBool = bool.fromEnvironment('someBool'); const someString = String.fromEnvironment('someString');
In the case of Flutter apps, fromEnvironment should only be called in a const expression because it won’t be available at runtime.
Defines in flutter can be passed to run and build:
flutter run --dart-define=someString=foo
flutter build apk --dart-define=someString=foo
Defines can be passed to the regular dart command through the undocumented
dart -DsomeString=foo bin/main.dart
This is not a solution to providing secret keys to a Flutter application, if a key is secret then it should not be shipped in your app.
It’s perfectly fine to include public keys in dart code and even push them to git, e.g. a token for the Google Maps API.