RemoteAdapter<T extends DataModelMixin<T>> class

An adapter base class for all remote 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 _RemoteAdapterSerialization.serialize
  • Watch methods such as Repository.watchOneNotifier
  • Access to the _RemoteAdapter.graph for subclasses or mixins

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

@JsonSerializable()
@DataRepository([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

RemoteAdapter(LocalAdapter<T> localAdapter, [InternalHolder<T>? _internalHolder])

Properties

adapters Map<String, RemoteAdapter<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
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
graph GraphNotifier
A GraphNotifier instance also available to adapters
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
INTERNAL: DO NOT USE
no setterinherited
internalWatch Watcher?
ONLY FOR FLUTTER DATA INTERNAL USE
getter/setter pairinherited
isInitialized bool
no setterinherited
localAdapter LocalAdapter<T>
finalinherited
offlineOperations Set<OfflineOperation<T>>
no setterinherited
ref Ref<Object?>
Give access to the dependency injection system
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type String
The pluralized and downcased DataHelpers.getType<T> version of type T by default.
no setterinherited

Methods

clear() Future<void>
inherited
delete(Object model, {bool? remote, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T?>
inherited
deleteLocal(T model, {bool notify = true}) → void
inherited
deserialize(Object? data) Future<DeserializedData<T>>
Returns a DeserializedData object when deserializing a given data.
inherited
dispose() → void
inherited
findAll({bool? remote, bool? background, Map<String, dynamic>? params, Map<String, String>? headers, bool? syncLocal, OnSuccessAll<T>? onSuccess, OnErrorAll<T>? onError, DataRequestLabel? label}) Future<List<T>>
inherited
findOne(Object id, {bool? remote, bool? background, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T?>
inherited
initialize({bool? remote, required Map<String, RemoteAdapter<DataModelMixin>> adapters, required Ref<Object?> ref}) Future<RemoteAdapter<T>>
inherited
isOfflineError(Object? error) bool
Determines whether error was an offline error.
inherited
keyForModelOrId(Object model) String
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
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
save(T model, {bool? remote, Map<String, dynamic>? params, Map<String, String>? headers, OnSuccessOne<T>? onSuccess, OnErrorOne<T>? onError, DataRequestLabel? label}) Future<T>
inherited
saveLocal(T model, {bool notify = true}) → T
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
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
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
watchAllNotifier({bool? remote, Map<String, dynamic>? params, Map<String, String>? headers, bool? syncLocal, String? finder, DataRequestLabel? label}) DataStateNotifier<List<T>>
inherited
watchOneNotifier(String key, {bool? remote, Map<String, dynamic>? params, Map<String, String>? headers, AlsoWatch<T>? alsoWatch, String? finder, DataRequestLabel? label}) DataStateNotifier<T?>
inherited

Operators

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