state method
void
state(
- StateKey stateKey,
- void build(
- StateBuilder builder
- StateKey? parent,
- InitialChild? initialChild,
Adds to the state tree a description of a state, identified by stateKey.
The behavior of the state is configured by calling methods on the StateBuilder that is
provided to the build callback.
enum Messages { toggle }
var offState = StateKey('off');
var onState = StateKey('on');
var builder = new StateTreeBuilder(initialState: offState);
// Describe a state
builder.state(offState, (b) {
// Define the behavior of the state
b.onMessageValue(Messages.toggle, (b) => b.goTo(onState));
});
The state can be declared as a child state, by providing a parent value referencing the
parent state. If the state is itself a parent state (that is, other states refer to it as a
parent), then initialChild must be provided, indicating which child state should be entered
when this state is entered.
Implementation
void state(
StateKey stateKey,
void Function(StateBuilder builder) build, {
StateKey? parent,
InitialChild? initialChild,
}) {
if (_stateBuilders.containsKey(stateKey)) {
throw StateError('State $stateKey has already been configured.');
}
var builder = _StateBuilder._(stateKey, parent, initialChild);
build(builder);
_addState(builder);
}