MutationBuilder<TData, TVariables, TOnMutateResult> class
Mutations
Builds its subtree from a mutation's result, and hands the builder the MutationController that starts a run.
MutationBuilder(
options: MutationOptions.simple(
mutationFn: (String name) => api.rename(id, name),
),
builder: (context, rename) => switch (rename.value) {
MutationPending() => const CircularProgressIndicator(),
MutationError(:final error) => Text('Could not rename: $error'),
_ => TextButton(
onPressed: () => rename.mutate('Kitchen'),
child: const Text('Rename'),
),
},
)
The widget owns the controller from its first build until it is disposed; do not dispose the one builder is handed. Disposing it does not cancel a run in flight — the mutation finishes and its options' callbacks run — so a write the user started is not lost when the widget goes. Call MutationController.cancel first when it should be.
The type arguments come from options: MutationOptions.simple, for a
mutation without an onMutate step, infers them from mutationFn.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- MutationBuilder
Constructors
-
MutationBuilder({Key? key, required MutationOptions<
TData, TVariables, TOnMutateResult> options, required Widget builder(BuildContext context, MutationController<TData, TVariables, TOnMutateResult> mutation), BuildWhen<MutationResult< ? buildWhen, QueryClient? client})TData, TVariables> > -
Observes a mutation with
optionsonclientor else the nearest QueryClientProvider's, and handsbuilderthe controller that starts it.const
Properties
-
builder
→ Widget Function(BuildContext context, MutationController<
TData, TVariables, TOnMutateResult> mutation) -
Builds this widget's subtree from the mutation, given its controller:
the current MutationResult is
mutation.value, and MutationController.mutate or MutationController.mutateAsync starts a run. Called on the first build and then whenever the result changes and buildWhen lets it through.final -
buildWhen
→ BuildWhen<
MutationResult< ?TData, TVariables> > -
Whether a change from the mutation result last built to the current one
is worth a rebuild;
nullrebuilds for every changed result. A mutation has noselect, so this is the only filter:final - client → QueryClient?
-
The client to run on;
nulluses the nearest QueryClientProvider's. A different client on a later build recreates the controller; see QueryBuilder.client.final - hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
options
→ MutationOptions<
TData, TVariables, TOnMutateResult> -
The mutation: its function and callbacks. Re-applied whenever the
parent rebuilds this widget, so the next run uses the latest ones.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< MutationBuilder< TData, TVariables, TOnMutateResult> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited