Flutter plugin to store data in secure storage
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
The flutter_secure_storage plugin can be used to store data safely in a Flutter application. Sensitive data is securely kept via this plugin, which offers keychain- and keystore-based implementations on iOS and Android, respectively.
Implementation
To your pubspec.yaml file, add the dependency for flutter_secure_storage:
dependencies:
flutter_secure_storage: ^5.0.2
Run the command flutter pub get to fetch the dependency.
Import the flutter_secure_storage package in your Dart file:
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
Check for the latest version on the plugin’s page.
Configure Android Version
In [project]/android/app/build.gradle set minSdkVersion to >= 18.
android {
...
defaultConfig {
...
minSdkVersion 18
...
}
}
Initialize an instance of FlutterSecureStorage:
final FlutterSecureStorage secureStorage = FlutterSecureStorage();
Store a key-value pair securely:
await secureStorage.write(key: 'keyName', value: 'secretValue');
Retrieve the value associated with a key:
String value = await secureStorage.read(key: 'keyName');
Update the value associated with a key:
await secureStorage.write(key: 'keyName', value: 'newSecretValue');
Delete a key-value pair:
await secureStorage.delete(key: 'keyName');
Read All Data
To read all the values, we will use the readAll method.
await _localStorage.readAll();
Delete All Data
To delete all entries, we will use the delete all method.
await _localStorage.deleteAll();
Reference
Write, read, and delete all data from local storage
Secure-local-storage-in-flutter
Flutter – How to save data locally?
flutter-how-to-save-data-locally
how-to-save-to-web-local-storage-in-flutter-web
https://stackoverflow.com/questions/56417667/how-to-save-to-web-local-storage-in-flutter-web
Reading, Writing, and Deleting API data in local-storage-in-flutter-web
securing-local-storage-flutter