This example project tests how we secure data in Flutter, such as API keys.
- Create the
.envfile inside the main directory. - Create the
env.dartfile. - For static variable
static String apiKey = _Envand run the new command (the old one deprecated)dart run build_runner buildordart run build_runner build--delete-conflicting-outputs. - Generated.
- Add the Key
static String apiKey = _Env.apiKey.
Important
For this example, keep the files with dummy/test API keys, but for a real project, you should add
them to the .gitignore file.
dart run build_runner build or dart run build_runner build --delete-conflicting-outputs
- Flutter SDK version: 3.41.2
- Dart Version: 3.11.0