NyStorage class

Base class to help manage local storage

Constructors

NyStorage()

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

addToCollection<T>(String key, {required T item, bool allowDuplicates = true, Map<Type, dynamic>? modelDecoders}) Future<void>
Add a newItem to the collection using a key.
clear(String key) Future<void>
Sets the key to null. @deprecated Use delete instead for consistent behavior.
delete(String key, {bool andFromBackpack = false}) Future<void>
Deletes associated value for the given key.
deleteAll({bool andFromBackpack = false, List<String>? excludeKeys}) Future<void>
Deletes all keys with associated values.
deleteCollection(String key, {bool andFromBackpack = false}) Future<void>
Deletes a collection from the given key. @deprecated Use delete instead for consistent behavior.
deleteFromCollection<T>(int index, {required String key}) Future<void>
Delete an item of a collection using a index and the collection key.
deleteFromCollectionWhere<T>(bool where(T value), {required String key}) Future<void>
Delete item(s) from a collection using a where query.
deleteMultiple(List<String> keys, {bool andFromBackpack = false}) Future<void>
Deletes multiple keys from local storage in batch.
deleteValueFromCollection<T>(String key, {required T value}) Future<void>
Delete a value from a collection using a key and the value you want to remove.
getTimeToLive(String key) Future<Duration?>
Gets the remaining time-to-live for a key with expiry. Returns null if the key doesn't exist or has no expiry set.
hasKey(String key) Future<bool>
Checks if a key exists in local storage.
isCollectionEmpty(String key) Future<bool>
Checks if a collection is empty
manager() → FlutterSecureStorage
migrateToEnvelopeFormat() Future<int>
Migrates legacy storage format to new envelope format. Call this during app initialization to convert old data. Returns the number of keys migrated.
read<T>(String key, {T? defaultValue, Map<Type, dynamic>? modelDecoders}) Future<T?>
Read a value from the local storage. Returns the value cast to type T, or defaultValue if not found. Supports both legacy format (separate _runtime_type key) and new envelope format.
readAll() Future<Map<String, String>>
Decrypts and returns all keys with associated values.
readCollection<T>(String key, {Map<Type, dynamic>? modelDecoders}) Future<List<T>>
Read the collection values using a key.
readJson<T>(String key, {T? defaultValue}) Future<T?>
Read a JSON value from the local storage. Returns the decoded JSON object, or defaultValue if not found.
readMultiple<T>(List<String> keys, {Map<Type, dynamic>? modelDecoders}) Future<Map<String, T?>>
Reads multiple keys from local storage in batch. Returns a map of key-value pairs. Missing keys will have null values.
readWithExpiry<T>(String key, {T? defaultValue, Map<Type, dynamic>? modelDecoders, bool deleteIfExpired = true}) Future<T?>
Read a value from local storage, respecting TTL expiration. If the value has expired, it will be deleted and null returned.
removeExpired() Future<int>
Removes all expired keys from storage. Returns the number of keys removed.
save(String key, dynamic object, {bool inBackpack = false}) Future<void>
Saves an object to local storage using an optimized envelope format. The envelope stores type metadata inline with the value, reducing I/O operations.
saveAll(Map<String, dynamic> items, {bool inBackpack = false}) Future<void>
Saves multiple key-value pairs to local storage in batch. More efficient than calling save multiple times.
saveCollection<T>(String key, List<T> collection) Future<void>
Save a list of objects to a collection using a key.
saveJson(String key, dynamic object, {bool inBackpack = false}) Future<void>
Saves a JSON object to local storage.
saveWithExpiry(String key, dynamic object, {required Duration ttl, bool inBackpack = false}) Future<void>
Saves an object to local storage with an expiration time (TTL). The value will be automatically removed when read after expiration.
syncToBackpack({bool overwrite = false}) Future<void>
Sync all the keys stored to the Backpack instance.
updateCollectionByIndex<T>(int index, T object(T item), {required String key}) Future<bool>
Update a value in the local storage by index.
updateCollectionWhere<T>(bool where(T value), {required String key, required T update(T value)}) Future<void>
Update item(s) in a collection using a where query.