post<M> method
Posts a message to be processed by the state machine when a transition occurs.
If getMessage is provided, the function will be evaluated when the transition occurs, and
the returned message will be posted. Otherwise a message must be provided.
var state1 = StateKey('s1');
var builder = StateTreeBuilder(initialState: state1);
builder.state(state1, (b) {
// Post a MyMessage message when this state is entered.
b.onEnter((b) => b.post(getMessage: (transCtx) => MyMessage()));
});
This action can be labeled when formatting a state tree by providing a label.
Implementation
void post<M>({
M Function(TransitionContext ctx)? getMessage,
M? message,
String? label,
}) {
if (getMessage == null && message == null) {
throw ArgumentError('getMessage or message must be provided');
} else if (getMessage != null && message != null) {
throw ArgumentError('One of getMessage or message must be provided');
}
var _getMessage = getMessage ?? (_) => message!;
_handler = _TransitionHandlerDescriptor.post<M>(_getMessage, label);
}