This example project tested how we keep secure the data in Flutter, example, api key(s).
- Create the .env 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" or dart run build_runner build --delete-conflicting-outputs. - Generated.
- Add the Key
static String apiKey = _Env.apiKey
.
For this example keeps the files with dummy/tested api key but for real project you have to add them in gitignore file.
dart run build_runner build or dart run build_runner build --delete-conflicting-outputs
Flutter SDK version: 3.24.4
Dart Version: 3.5.4
https://pub.dev/packages/envied
https://medium.com/@r1n1os/securing-sensitive-data-in-flutter-d0a8e060a11e
https://github.com/r1n1os/Secure-Sensitive-Data-Example