Question
write,read, delete all data from localstorage
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,Deleting api data in local-storage-in-flutter-web
securing-local-storage-flutter
Coding example of secure storage
Secure Local Storage in Flutter
Implementation
We will use a flutter plugin called flutter_secure_storage .
Add the following to your pubspec.yaml file:
dependencies:
...
flutter_secure_storage: ^4.2.0
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
...
}
}
Create Instance
Import flutter_secure_storage in your file and create an instance of it.
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
FlutterSecureStorage _localStorage = new FlutterSecureStorage();
Write Data
To insert a key-value pair in the storage, we will use the write method.
We need to pass key and value to this method.
await _localStorage.write(key: key, value: value);
key and value should be a string.
If the key already exists, the value will get replaced.
If we pass a null value and the key already exists, it will get deleted.
Its return type is void.
Read Data
To read a value for a particular key, we will use the read method.
We need to pass the key to this method.
await _localStorage.read(key: key);
key should be a string.
If the key exists, the value will be returned.
If the key doesn't exist the null will be returned.
Its return type is always a string.
Read All Data
To read all the values, we will use the readAll method.
await _localStorage.readAll();
It will return all the key-value pairs as a Map.
Delete Data
To delete an entry, we will use the delete method.
We need to pass the key to this method.
await _localStorage.delete(key: key);
key should be a string.
Its return type is void.
Delete All Data
To delete all entries, we will use the deleteAll method.
await _localStorage.deleteAll();
Its return type is void.
Coding example of flutter secure storage
save the data using flutter secure storage dependency
final secureStorage = FlutterSecureStorage();
await secureStorage.write(key: 'orgRoleId', value: orgRoleId.toString()); // Save orgRoleId
Get data using flutter secure storage
final orgSlug = widget.orgSlug;
final secureStorage = FlutterSecureStorage();
final orgRoleId = await secureStorage.read(key: 'orgRoleId');
setState(() {
_userRole = determineUserRole(orgRoleId); // Use the mixin to determine the role
});
apply logic in mixins dart file
secure-local-storage-in-flutter-
https://stackoverflow.com/questions/66081455/flutter-how-to-save-data-locally
securing-local-storage-flutter
https://stackoverflow.com/questions/56417667/how-to-save-to-web-local-storage-in-flutter-web
Top comments (0)