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 : LocalAdapter(ProviderReference _ref) 9 2 : : graph = _ref.read(graphNotifierProvider); 10 : 11 : @protected 12 : final GraphNotifier graph; 13 : 14 : FutureOr<LocalAdapter<T>> initialize(); 15 : 16 : // protected API 17 : 18 : /// Returns all models of type [T] in local storage. 19 : @protected 20 : @visibleForTesting 21 : List<T> findAll(); 22 : 23 : /// Finds model of type [T] by [key] in local storage. 24 : @protected 25 : @visibleForTesting 26 : T? findOne(String key); 27 : 28 : /// Saves model of type [T] with [key] in local storage. 29 : /// 30 : /// By default notifies this modification to the associated [GraphNotifier]. 31 : @protected 32 : @visibleForTesting 33 : Future<T> save(String key, T model, {bool notify = true}); 34 : 35 : /// Deletes model of type [T] with [key] from local storage. 36 : /// 37 : /// By default notifies this modification to the associated [GraphNotifier]. 38 : @protected 39 : @visibleForTesting 40 : Future<void> delete(String key); 41 : 42 : /// Deletes all models of type [T] in local storage. 43 : @protected 44 : @visibleForTesting 45 : Future<void> clear(); 46 : 47 : // public abstract methods 48 : 49 : Map<String, dynamic> serialize(T model); 50 : 51 : T deserialize(Map<String, dynamic> map); 52 : 53 : Map<String, Map<String, Object?>> relationshipsFor([T model]); 54 : }