import 'package:cookie_jar/cookie_jar.dart'; import 'package:hive_flutter/adapters.dart'; class HiveStorage implements Storage { final String boxName; final String? boxPath; HiveStorage(this.boxName, {this.boxPath}); bool _initialized = false; late final Box _box; Future? _initFuture; Future init(bool persistSession, bool ignoreExpires) => _initFuture ??= _init(persistSession, ignoreExpires); Future _init(bool persistSession, bool ignoreExpires) async { if (_initialized) return; _initialized = true; _box = await Hive.openBox(boxName, path: boxPath); print('init() finished'); } @override Future read(String key) async { await _initFuture; return _box.get(key); } @override Future write(String key, String value) => _box.put(key, value); @override Future delete(String key) => _box.delete(key); @override Future deleteAll(List keys) => _box.deleteAll(keys); }