SecureStorageUtil class
Production-Ready Secure Storage Utility Class
A high-performance, encrypted local storage solution for Flutter Features:
- AES-256-CBC encryption with unique IVs per encryption
- Fast read/write operations with error handling and retry logic
- Type-safe storage (String, int, bool, double, Map, List)
- Singleton pattern for global access
- App-specific encryption key with rotation support
- Comprehensive error handling and logging
- Data versioning and migration support
- Automatic cleanup on app reinstallation
- In-memory caching for frequently accessed data
- Thread-safe operations with locks
Constructors
- SecureStorageUtil()
-
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
batchRead(
List< String> keys) → Future<Map< String, String> > - Batch read operations
-
batchWrite(
Map< String, dynamic> data) → Future<void> - Batch write operations for better performance (parallel execution)
-
clearAll(
) → Future< void> - Clear all stored data (except encryption key and version)
-
clearCache(
) → void - Clear in-memory cache
-
containsKey(
String key) → Future< bool> - Check if a key exists
-
exportData(
) → Future< Map< String, String> > - Export all data (encrypted) for backup purposes
-
getAllKeys(
) → Future< List< String> > - Get all keys (excluding internal keys)
-
getBool(
String key, {bool? defaultValue}) → Future< bool?> - Retrieve a bool value
-
getDouble(
String key, {double? defaultValue}) → Future< double?> - Retrieve a double value
-
getInt(
String key, {int? defaultValue}) → Future< int?> - Retrieve an int value
-
getList(
String key, {List? defaultValue}) → Future< List?> - Retrieve a List
-
getMap(
String key, {Map< String, dynamic> ? defaultValue}) → Future<Map< String, dynamic> ?> - Retrieve a Map
-
getObject<
T> (String key, T fromJson(Map< String, dynamic> ), {T? defaultValue}) → Future<T?> - Retrieve a generic object with type conversion
-
getStorageStats(
) → Future< Map< String, dynamic> > - Get storage statistics
-
getString(
String key, {String? defaultValue}) → Future< String?> - Retrieve a String value
-
importData(
Map< String, String> data) → Future<void> - Import data (encrypted) from backup
-
init(
{bool enableCache = false}) → Future< void> - Initialize the secure storage Must be called before using any storage operations
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
String key) → Future< void> - Delete a specific key
-
removeAll(
List< String> keys) → Future<void> - Delete multiple keys at once
-
resetStorage(
) → Future< void> - Reset the entire storage including encryption key
-
rotateEncryptionKey(
) → Future< void> - Rotate the encryption key (advanced feature)
-
setBool(
String key, bool value) → Future< void> - Store a bool value
-
setDouble(
String key, double value) → Future< void> - Store a double value
-
setInt(
String key, int value) → Future< void> - Store an int value
-
setList(
String key, List value) → Future< void> - Store a List (as JSON)
-
setMap(
String key, Map< String, dynamic> value) → Future<void> - Store a Map (as JSON)
-
setObject(
String key, Map< String, dynamic> jsonObject) → Future<void> - Store a generic object (must be JSON serializable)
-
setString(
String key, String value) → Future< void> - Store a String value
-
toString(
) → String -
A string representation of this object.
inherited
-
validateAllData(
) → Future< Map< String, bool> > - Validate integrity of all stored data Returns a map of key -> isValid
-
validateKey(
String key) → Future< bool> - Validate data integrity for a specific key Returns true if data can be successfully decrypted
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited