hive_local_storage 0.0.5 copy "hive_local_storage: ^0.0.5" to clipboard
hive_local_storage: ^0.0.5 copied to clipboard

A cache helper which uses hive and flutter_secure_storage to make ease to store session and encrypted data

hive_local_storage #


A utility package to storage user session and cache values in hive box

  • uses hive for caching
  • uses flutter_secure_storage to storage encryption key of secured hive box for session storage

Get Started #

dependencies:
  hive_local_storage: latest

if you want to use custom class for hive you need to add hive_generator in your dev_dependencies

dev_dependencies:
  build_runner: latest
  hive_generator: latest

Usage #

  import 'package:hive_local_storage/hive_local_storage.dart';

Write data

   /// initialize local_storage
  final localStorage = await LocalStorage.getInstance();
  
  // to store value in normal box
  await localStorage.put<int>(key:'count',value:0);
  
  // to store value in encrypted box
  await localStorage.put<String>(key:'key',value:'some important key',useEncryption:true);

  // write multiple values
  await localStorage.putAll(Map<String,dynamic> entries);
  
  // write multiple values in encrypted box
  await localStorage.putAll(entries:{},useEncryption:true);
  
  // to store use session
  final session = Session()
                ..accessToken = 'accessToken'
                ..refreshToken ='refreshToken'
                ..expiresIn = 1231232;
  await localStorage.saveSession(session);

Read data

   /// initialize local_storage
  final localStorage = await LocalStorage.getInstance();
  
  // to get value from normal box
  final count  = await localStorage.get<int>(key:'count');
  
  // to get value from encrypted box
  final key = await localStorage.get<String>(key:'key',useEncryption:true);
  
  // to get session
  final Session? session = await localStorage.getSession();
  
  //to check whether session has present or not
  final hasSession = await localStorage.hasSession();

Delete data

   /// initialize local_storage
  final localStorage = await LocalStorage.getInstance();
  
  // remove value from normal box
   await localStorage.remove(key:'count');
   
   // remove all from normal box
   await localStorage.clear();
  
  // remove value from encrypted box
  await localStorage.remove(key:'key',useEncryption:true);
  
  
  //remove all values form encrypted box
  await localStorage.clear(useEncryption:true);
  
  // remove session
  await localStorage.clearSession();

TODO: #

  • support for TypeAdapters
  • add Test
7
likes
0
pub points
83%
popularity

Publisher

verified publisherkishormainali.com

A cache helper which uses hive and flutter_secure_storage to make ease to store session and encrypted data

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_secure_storage, hive, hive_flutter

More

Packages that depend on hive_local_storage