This example project tests how we secure data in Flutter, such as API keys.
- Create the
.env
file inside the main directory. - Create the
env.dart
file. - For static variable
static String apiKey = _Env
and run the new command (the old one deprecated)dart run build_runner build
ordart run build_runner build--delete-conflicting-outputs
. - Generated.
- Add the Key
static String apiKey = _Env.apiKey
.
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.27.1
Dart Version: 3.6.0
https://pub.dev/packages/envied
https://medium.com/@r1n1os/securing-sensitive-data-in-flutter-d0a8e060a11e
https://github.com/r1n1os/Secure-Sensitive-Data-Example