whenWith<C2> method
- FutureOr<
C2> context(- TransitionHandlerContext<
D, C> ctx
- TransitionHandlerContext<
- FutureOr<
bool> condition(- TransitionHandlerContext<
D, C2> ctx
- TransitionHandlerContext<
- void buildTrueHandler(
- TransitionHandlerBuilder<
D, C2> builder
- TransitionHandlerBuilder<
- String? label,
Describes transition behavior that may be run conditionally, sharing a context value among conditions.
This method is similar to when, but a context function providing a contextual value is
first called before evaluating any conditions. The context value can be accessed by the
conditions with the TransitionHandlerContext.context property. This may be useful in
avoiding generating the context value repeatedly in each condition.
When the transition occurs, the condition function is evaluated. If the function returns
true, the behavior described by the buildTrue callback will take place.
The returned TransitionHandlerWhenBuilder may be used to define additional conditional behavior, including a fallback TransitionHandlerWhenBuilder.otherwise condition.
If more than one condition is defined, the conditions are evaluated in the order they are defined by calls to TransitionHandlerWhenBuilder.when.
Implementation
TransitionHandlerWhenBuilder<D, C2> whenWith<C2>(
FutureOr<C2> Function(TransitionHandlerContext<D, C> ctx) context,
FutureOr<bool> Function(TransitionHandlerContext<D, C2> ctx) condition,
void Function(TransitionHandlerBuilder<D, C2> builder) buildTrueHandler, {
String? label,
}) {
var contextRef = Ref<C2?>(null);
var conditions = <TransitionConditionDescriptor<C2>>[];
var whenBuilder = TransitionHandlerWhenBuilder<D, C2>._(
conditions,
() => TransitionHandlerBuilder<D, C2>._(_forState, _log, (_) => contextRef.value!),
);
whenBuilder.when(condition, buildTrueHandler, label: label);
_descriptor = makeWhenWithContextDescriptor<D, C, C2>(
context,
conditions,
_makeContext,
_log,
label,
);
return whenBuilder;
}