Adapter<T extends DataModelMixin<T>> class abstract

An adapter base class for all operations for type T.

Includes:

  • Remote methods such as _RemoteAdapter.findAll or _RemoteAdapter.save
  • Configuration methods and getters like _RemoteAdapter.baseUrl or _RemoteAdapter.urlForFindAll
  • Serialization methods like _SerializationAdapter.serialize
  • Watch methods such as _WatchAdapter.watchOneNotifier
  • Access to the _BaseAdapter.core for subclasses or mixins

This class is meant to be extended via mixing in new adapters. This can be done with the DataAdapter annotation on a DataModelMixin class:

@JsonSerializable()
@DataAdapter([MyAppAdapter])
class Todo with DataModel<Todo> {
  @override
  final int? id;
  final String title;
  final bool completed;

  Todo({this.id, required this.title, this.completed = false});
}

Identity in this layer is enforced by IDs.

Constructors

Adapter(Ref<Object?> ref, [InternalHolder<T>? _internalHolder])

Properties

adapters Map<String, Adapter<DataModelMixin>>
All adapters for the relationship subgraph of T and their relationships.
no setterinherited
baseUrl String
Returns the base URL for this type T.
no setterinherited
core CoreNotifier
finalinherited
countLocal int
Counts all models of type T in local storage.
no setterinherited
db → Database
no setterinherited
defaultHeaders FutureOr<Map<String, String>>
A Map representing default HTTP headers.
no setterinherited
defaultParams FutureOr<Map<String, dynamic>>
A Map representing default HTTP query parameters. Defaults to empty.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
httpClient → Client
An http.Client used to make an HTTP request.
no setterinherited
internalType String
no setterinherited
internalWatch Watcher?
ONLY FOR FLUTTER DATA INTERNAL USE
getter/setter pairinherited
isInitialized bool
getter/setter pairinherited
keys Set<String>
Gets all keys of type T in local storage.
no setterinherited
logLevel int
Set log level.
getter/setter pairinherited
offlineOperations Set<OfflineOperation<T>>
no setterinherited
ref Ref<Object?>
Give access to the dependency injection system
no setterinherited
relationshipMetas Map<String, RelationshipMeta<DataModelMixin>>
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storage LocalStorage
finalinherited
type String
The pluralized and downcased DataHelpers.getType<T> version of type T by default.
no setterinherited

Methods

clearLocal({bool notify = true}) Future<void>
Deletes all models of type T in local storage.
inherited
delete(Object model, {bool remote = true, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T?>
Deletes model of type T.
inherited
deleteLocal(T model, {bool notify = true}) → void
Deletes model of type T from local storage.
inherited
deleteLocalById(Object id, {bool notify = true}) → void
Deletes model with id from local storage.
inherited
deleteLocalByKeys(Iterable<String> keys, {bool notify = true}) → void
Deletes models with keys from local storage.
inherited
deserialize(Object? data, {String? key, bool async = true}) Future<DeserializedData<T>>
Returns a DeserializedData object when deserializing a given data.
inherited
deserializeAndSave(Object? data, {String? key, bool notify = true, bool ignoreReturn = false}) Future<DeserializedData<T>>
inherited
deserializeFromResult(ResultSet result) List<T>
inherited
deserializeLocal(Map<String, dynamic> map, {String? key}) → T
inherited
dispose() → void
inherited
exists(String key) bool
Whether key exists in local storage.
inherited
findAll({bool remote = true, bool background = false, Map<String, dynamic>? params, Map<String, String>? headers, bool syncLocal = false, OnSuccessAll<T>? onSuccess, OnErrorAll<T>? onError, DataRequestLabel? label}) Future<List<T>>
Returns all models of type T.
inherited
findAllLocal() List<T>
Returns all models of type T in local storage.
inherited
findManyLocal(Iterable<String> keys) List<T>
Finds many models of type T by keys in local storage.
inherited
findOne(Object id, {bool remote = true, bool? background, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T?>
Returns model of type T by id.
inherited
findOneLocal(String? key) → T?
Finds model of type T by key in local storage.
inherited
findOneLocalById(Object id) → T?
inherited
initialize({required Ref<Object?> ref}) Future<Adapter<T>>
inherited
initModel(T model, {String? key, dynamic onModelInitialized(T)?}) → T
inherited
internalWrapStopInit(Function fn, {String? key}) → T
inherited
isOfflineError(Object? error) bool
Determines whether error was an offline error.
inherited
log(DataRequestLabel label, String message, {int logLevel = 1}) → void
inherited
methodForDelete(dynamic id, Map<String, dynamic> params) DataRequestMethod
Returns HTTP method for delete. Defaults to DELETE.
inherited
methodForFindAll(Map<String, dynamic> params) DataRequestMethod
Returns HTTP method for findAll. Defaults to GET.
inherited
methodForFindOne(dynamic id, Map<String, dynamic> params) DataRequestMethod
Returns HTTP method for findOne. Defaults to GET.
inherited
methodForSave(dynamic id, Map<String, dynamic> params) DataRequestMethod
Returns HTTP method for save. Defaults to PATCH if id is present, or POST otherwise.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifierFor(T model) DataStateNotifier<T?>
Notifier for watched model (local)
inherited
onError<R>(DataException e, DataRequestLabel? label) FutureOr<R?>
Implements global request error handling.
inherited
onInitialized() Future<void>
inherited
onModelInitialized(T model) → void
After model initialization hook
inherited
onSuccess<R>(DataResponse response, DataRequestLabel label) FutureOr<R?>
inherited
runInIsolate<R>(FutureOr<R> fn(Adapter<DataModelMixin> adapter)) Future<R>
inherited
save(T model, {bool remote = true, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T>
Saves model of type T.
inherited
saveLocal(T model, {bool notify = true}) → T
Saves model of type T in local storage.
inherited
saveManyLocal(Iterable<DataModelMixin<DataModelMixin>> models, {bool notify = true, bool async = true}) Future<List<String>?>
inherited
sendRequest<R>(Uri uri, {DataRequestMethod method = DataRequestMethod.GET, Map<String, String>? headers, Object? body, _OnSuccessGeneric<R>? onSuccess, _OnErrorGeneric<R>? onError, bool omitDefaultParams = false, bool returnBytes = false, DataRequestLabel? label, bool closeClientAfterRequest = true}) Future<R?>
The function used to perform an HTTP request and return an R.
inherited
serialize(T model, {bool withRelationships = true}) Future<Map<String, dynamic>>
Returns a serialized version of a model of T, as a Map<String, dynamic> ready to be JSON-encoded.
inherited
serializeLocal(T model, {bool withRelationships = true}) Map<String, dynamic>
inherited
shouldLoadRemoteAll(bool remote, Map<String, dynamic> params, Map<String, String> headers) bool
Returns whether calling findAll should trigger a remote call.
inherited
shouldLoadRemoteOne(Object? id, bool remote, Map<String, dynamic> params, Map<String, String> headers) bool
Returns whether calling findOne should initiate an HTTP call.
inherited
toString() String
A string representation of this object.
inherited
transformDeserialize(Map<String, dynamic> map) Map<String, dynamic>
inherited
transformSerialize(Map<String, dynamic> map, {bool withRelationships = true}) Map<String, dynamic>
inherited
urlForDelete(dynamic id, Map<String, dynamic> params) String
Returns URL for delete. Defaults to type/id.
inherited
urlForFindAll(Map<String, dynamic> params) String
Returns URL for findAll. Defaults to type.
inherited
urlForFindOne(dynamic id, Map<String, dynamic> params) String
Returns URL for findOne. Defaults to type/id.
inherited
urlForSave(dynamic id, Map<String, dynamic> params) String
Returns URL for save. Defaults to type/id (if id is present).
inherited
watch(T model) → T
Watch this model (local)
inherited
watchAll({bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, bool syncLocal = false, String? finder, DataRequestLabel? label}) DataState<List<T>>
Watches a provider wrapping watchAllNotifier which allows the watcher to be notified of changes on any model of this type.
inherited
watchAllNotifier({bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, bool syncLocal = false, String? finder, DataRequestLabel? label}) DataStateNotifier<List<T>>
inherited
watchAllProvider({bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, bool syncLocal = false, String? finder, DataRequestLabel? label}) AutoDisposeStateNotifierProvider<DataStateNotifier<List<T>>, DataState<List<T>>>
inherited
watchOne(Object model, {bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, AlsoWatch<T>? alsoWatch, String? finder, DataRequestLabel? label}) DataState<T?>
Watches a provider wrapping watchOneNotifier which allows the watcher to be notified of changes on a specific model of this type, optionally reacting to selected relationships of this model via alsoWatch.
inherited
watchOneNotifier(Object model, {bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, AlsoWatch<T>? alsoWatch, String? finder, DataRequestLabel? label}) DataStateNotifier<T?>
inherited
watchOneProvider(Object model, {bool remote = false, Map<String, dynamic>? params, Map<String, String>? headers, AlsoWatch<T>? alsoWatch, String? finder, DataRequestLabel? label}) AutoDisposeStateNotifierProvider<DataStateNotifier<T?>, DataState<T?>>
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited