Channel<P> class
Indicates that a value of type P must be provided when entering a state.
Channels are intended as a contract indicating that in order to transition to a particular
state, additional contextual information of type P must be provided by the transition source.
class SubmitCredentials {}
class AuthenticatedUser {}
class AuthFuture {
final FutureOr<AuthenticatedUser?> futureOr;
AuthFuture(this.futureOr);
}
var loginState = StateKey('login');
var authenticatingState = StateKey('authenticating');
var authenticatingChannel = Channel<SubmitCredentials>(authenticatingState);
AuthFuture _login(SubmitCredentials creds) {
// ...Perform authentication
return AuthFuture(Future.value(AuthenticatedUser()));
}
var treeBuilder = StateTreeBuilder(initialState: loginState);
treeBuilder.state(loginState, (b) {
b.onMessage<SubmitCredentials>((b) {
// Provide a SubmitCredentials value when entering authenticating state
b.enterChannel(authenticatingChannel, (ctx) => ctx.message);
});
});
treeBuilder.state(authenticatingState, (b) {
b.onEnterFromChannel<SubmitCredentials>(authenticatingChannel, (b) {
// The context argument provides access to the SubmitCredentials value
b.post<AuthFuture>(getMessage: (ctx) => _login(ctx.context));
});
});
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited