part of '../spotify.dart'; // ignore: invalid_use_of_internal_member mixin Persistence on BuildlessAsyncNotifier { LazyBox get store => Hive.lazyBox("spotube_cache"); FutureOr fromJson(Map json); Map toJson(T data); FutureOr onInit() {} Future load() async { final json = await store.get(runtimeType.toString()); if (json != null || (json is Map && json.entries.isNotEmpty) || (json is List && json.isNotEmpty)) { state = AsyncData( await fromJson( PersistedStateNotifier.castNestedJson(json), ), ); } await onInit(); } Future save() async { await store.put( runtimeType.toString(), state.value == null ? null : toJson(state.value as T), ); } @override set state(AsyncValue value) { if (state == value) return; super.state = value; save(); } }