Keychain/Keystore persistent Storage implementation.

This package is an addon to the single_item_storage package and offers a Storage implementation using the flutter_secure_storage package and dart JSON converters, json.encode and json.decode, to store items.

Getting started

Create a new instance by providing fromMap and toMap item converters, itemKey as key for this item in keychain, and an optional secureStore instance. Additionally you can add iOS and Android options. If options are not added, the default ones will be used.

Storage<User> storage = CachedStorage<User>(SecureStorage(
  itemKey: 'model.user.key',
  fromMap: (map) => User.fromMap(map),
  toMap: (item) => item.toMap(),
  iosOptions: IOSOptions(), 
  androidOptions: AndroidOptions(),

class User {
  final String id;
  final String email;

  factory User.fromMap(Map<String, dynamic> json) => _$UserFromJson(json);
  Map<String, dynamic> toMap() => _$UserToJson(this);


To store primitive values that don't need a converter use the .primitive named constructor.

/* Supported primitive types: 
 - bool
 - double
 - int
 - String
SecureStorage<int>.primitive(itemKey: 'cow_counter')

If the secureStorage is omitted, then an instance of FlutterSecureStorage is used.

When defining the to/from map converter mind that the map values can only be: number, boolean, string, null, list or a map with string keys as defined in json.encode and json.decode from the dart:convert package.

This example uses json_serializable as Map converter for convenience.