LocalStorage class

A wrapper class for session and cache box uses Hive

Properties

accessToken String?
accessToken getter to access accessToken
no setter
createdAt DateTime?
createdAt getter to access createdAt
no setter
hashCode int
The hash code for this object.
no setterinherited
hasSession bool
hasSession checks whether Box<Session> is not empty or Session is not null
no setter
isTokenExpired bool?
isTokenExpired checks whether token is expired or not
no setter
onSessionChange Stream<bool>
onSessionChange returns stream of bool when data changes on box
no setter
refreshToken String?
refreshToken getter to access refreshToken
no setter
remainingTokenDuration Duration
remainingTokenDuration returns remaining time of token
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
updatedAt DateTime?
updatedAt getter to access updatedAt
no setter

Methods

add<T>({required String boxName, required T value}) Future<void>
add add data to custom box
addAll<T>({required String boxName, required List<T> values}) Future<void>
addAll add multiple data to custom box
clear() Future<int>
clear clear all values from box
clearAll() Future<void>
clearAll clear all values from both session box and cache box does not clears box created using openBox()
clearSession() Future<void>
clearSession removes the Session value from Box
closeAll() Future<void>
close all the opened box
delete<T>({required String boxName, required T value, bool filter(T)?}) Future<void>
delete delete item from data
deleteAll() Future<void>
delete all the opened box
get<T>({required String key, T? defaultValue, String? boxName}) → T?
get get data from cache box returns defaultValue if key is not found returns null if defaultValue is not provided if boxName is provided then it will get data from custom box
getBox<T>(String name) Future<Box<T>>
getBox returns the previously opened box if exists otherwise opens the box and returns new box
getList<T>({required String key, List<T> defaultValue = const []}) List<T>
getList get list data
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openBox<T>({required String boxName, HiveCipher? customCipher, int? typeId}) FutureOr<Box<T>>
openBox open custom box
put<T>({required String key, required T value, String? boxName}) Future<void>
put puts data in cache box if boxName is provided then it will put data in custom box
putAll({required Map<String, dynamic> entries}) Future<void>
save puts value in box with key
putList<T>({required String key, required List<T> value}) Future<void>
save list of data
remove<T>({required String key, String? boxName}) Future<void>
remove removes data from cache box if boxName is provided then it will remove data from custom box
saveToken(String token, [String? refreshToken]) Future<void>
saveToken updates access token if exists or saves new one if not updates refresh token
toCacheMap() Map<String, Map<String, dynamic>?>
convert box to map
toString() String
A string representation of this object.
inherited
update<T>({required String boxName, required T value, bool filter(T)?}) Future<void>
update update item from data
values<T>(String boxName) List<T>
values get all the values from custom box
watchKey<T>({required String key, String? boxName}) Stream<T?>
watch watch specific key for value changed

Operators

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

Static Methods

getInstance({String? storageDirectory, void registerAdapters()?, HiveCipher? customCipher}) Future<LocalStorage>
initialize the dependencies register the adapters
readAndClose<T>({required String key, required String boxName}) Future<T?>
readAndClose read value from box and close the box
writeAndClose<T>({required String boxName, required String key, required T value}) Future<void>
writeAndClose write value to box and close the box

Constants

cacheKey → const String
cache key
sessionKey → const String
session key