MessageHandlerBuilder<M, D, C> class
Provides methods for describing how a state, carrying state data of type D, behaves in
response to a message of type M.
In some specialized situations, the builder may also carry a contextual value type C. In the
general case C will be void.
A MessageHandlerBuilder is provided to the build callback provided to StateBuilder.onMessage, and is used to describe how messages of a particular type are handled by a state.
class MyMessage {}
var state1 = StateKey('s1');
var state2 = StateKey('s2');
var builder = StateTreeBuilder(initialState: state1);
builder.state(state1, (b) {
// Describe how state responds to MyMessage messages
b.onMessage<MyMessage>((b) => b.goTo(state2));
});
Constructors
-
MessageHandlerBuilder(StateKey forState, FutureOr<
C> makeContext(MessageContext), Logger log, String? messageName)
Properties
-
act
→ MessageActionBuilder<
M, D, C> -
A MessageActionBuilder that can be used to specify actions that should take place when
handling messages.
latefinalinherited
-
descriptor
↔ MessageHandlerDescriptor<
C> ? -
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
action(
MessageActionDescriptor< M, D, C> action, [ActionResult actionResult = ActionResult.handled]) → void - Indicates that an action should take place when handling a message, and that no state transition should occur.
-
enterChannel<
P> (Channel< P> channel, FutureOr<P> payload(MessageHandlerContext<M, D, C> ), {MessageActionDescriptor<M, D, C> ? action, bool reenterTarget = false}) → void -
Indicates that
channelshould be entered and a transition to the channels state should occur.inherited -
goTo(
StateKey targetState, {TransitionHandler? transitionAction, FutureOr< Object?> payload(MessageHandlerContext<M, D, C> ctx)?, MessageActionDescriptor<M, D, C> ? action, bool reenterTarget = false, String? label}) → void -
Indicates that a transition to
targetStateshould occur.inherited -
goToSelf(
{TransitionHandler? transitionAction, MessageActionDescriptor< M, D, C> ? action, String? label}) → void - Indicates that the message has been handled, and that a self transition should occur.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stay(
{MessageActionDescriptor< M, D, C> ? action}) → void - Indicates that the message has been handled, and no state transition should occur.
-
toString(
) → String -
A string representation of this object.
inherited
-
unhandled(
{MessageActionDescriptor< M, D, C> ? action}) → void - Indicates that the message has not been handled, and the message should be dispatched to ancestor states for processing.
-
when(
FutureOr< bool> condition(MessageHandlerContext<M, D, C> ), void buildTrue(MessageHandlerBuilder<M, D, C> builder), {String? label}) → MessageHandlerWhenBuilder<M, D, C> - Describes message handling behavior that may be run conditionally, sharing a context value among conditions.
-
whenResult<
T> (FutureOr< Result< result(MessageHandlerContext<T> >M, D, C> ), void buildSuccess(MessageHandlerBuilder<M, D, T> builder), {String? label}) → MessageHandlerWhenResultBuilder<M, D, C, T> -
Describes message handling behavior that runs conditionally, depending on a
Resultvalue. -
whenWith<
C2> (FutureOr< C2> context(MessageHandlerContext<M, D, C> ctx), FutureOr<bool> condition(MessageHandlerContext<M, D, C2> ctx), void buildTrue(MessageHandlerBuilder<M, D, C2> builder), {String? label}) → MessageHandlerWhenBuilder<M, D, C2> - Describes message handling behavior that may be run conditionally, sharing a context value among conditions.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited