Line data Source code
1 : part of flutter_data; 2 : 3 : /// An adapter interface to access local storage 4 : /// 5 : /// See also: [HiveLocalAdapter] 6 : abstract class LocalAdapter<T extends DataModel<T>> with _Lifecycle { 7 1 : @protected 8 1 : LocalAdapter(Reader read) : graph = read(graphNotifierProvider); 9 : 10 : @protected 11 : final GraphNotifier graph; 12 : 13 : FutureOr<LocalAdapter<T>> initialize(); 14 : 15 : // protected API 16 : 17 : /// Returns all models of type [T] in local storage. 18 : List<T> findAll(); 19 : 20 : /// Finds model of type [T] by [key] in local storage. 21 : T? findOne(String key); 22 : 23 : /// Saves model of type [T] with [key] in local storage. 24 : /// 25 : /// By default notifies this modification to the associated [GraphNotifier]. 26 : @protected 27 : @visibleForTesting 28 : Future<T> save(String key, T model, {bool notify = true}); 29 : 30 : /// Deletes model of type [T] with [key] from local storage. 31 : /// 32 : /// By default notifies this modification to the associated [GraphNotifier]. 33 : @protected 34 : @visibleForTesting 35 : Future<void> delete(String key); 36 : 37 : /// Deletes all models of type [T] in local storage. 38 : @protected 39 : @visibleForTesting 40 : Future<void> clear(); 41 : 42 : // public abstract methods 43 : 44 : Map<String, dynamic> serialize(T model); 45 : 46 : T deserialize(Map<String, dynamic> map); 47 : 48 : Map<String, Map<String, Object?>> relationshipsFor([T model]); 49 : }