onMessageWithData<M, D2> method

void onMessageWithData<M, D2>(
  1. void build(
    1. MessageHandlerBuilder<M, D, D2> b
    )
)

Describes how messages of type M should be handled by this state, when provided ancestor state data of type D2.

This method can be used when the message handler for a state requires access to state data from one of its ancestor states.

The build function is called with a TransitionHandlerBuilder that can be used to describe the behavior of the exit transition.

Implementation

void onMessageWithData<M, D2>(void Function(MessageHandlerBuilder<M, D, D2> b) build) {
  var builder = MessageHandlerBuilder<M, D, D2>(
    key,
    (msgCtx) => msgCtx.dataValueOrThrow<D2>(),
    _log,
    null,
  );
  build(builder);
  if (builder.descriptor != null) {
    _messageHandlerMap[M] = builder.descriptor!;
  }
}