Mutation<ReturnType, Arg> class

Mutation is used to create, update and delete data from an asynchronous source.

Add a key for referencing the mutation. Useful to listen to the state of the mutation in multiple places in the app. If null no mutation cache will be set. key must be a serializable value.

The mutation is an asynchronous queryFn. It should return a Future of type ReturnType and takes any argument of type Arg.

The mutation takes multiple lifecycle callbacks:

  • onStartMutation is called before the mutation _queryFn is run.
  • onSuccess is called after the _queryFn has completed with no error.
  • onError is called if the queryFn throws and error.

After a mutation it is common to invalidateQueries. Pass a list of query keys to invalidateQueries and next time they are called they will be fetched. Alternatively for more control of when invalidation happens use invalidateQuery at any time.

To invalidate and refetch a query use refetchQueries

Constructors

Mutation({Object? key, OnStartMutateCallback<Arg>? onStartMutation, OnSuccessCallback<ReturnType, Arg>? onSuccess, OnErrorCallback<Arg>? onError, required MutationQueryCallback<ReturnType, Arg> queryFn, List<Object>? invalidateQueries, List<Object>? refetchQueries})
Mutation is used to create, update and delete data from an asynchronous source.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
key String?
A stringified key to reference the mutation.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state MutationState<ReturnType>
Current MutationState of the mutation.
no setter
stream Stream<MutationState<ReturnType>>
Stream the state of the query.
no setter

Methods

mutate([Arg? arg]) Future<MutationState<ReturnType?>>
Starts the mutation with the given arg.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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