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));
  });
});

Constructors

Channel(StateKey to, {String? label})
Constructs a channel for the to state.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
label String?
A descriptive label for this channel.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
to StateKey
The state to enter for this channel.
final

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