createState<T extends S> method

T createState<T extends S>(
  1. T buildState()
)
inherited

Creates a new state by invoking the provided buildState function.

The buildState function should return an instance of a class that extends IState. The created state is automatically bound to the current binding zone using BindingZone.autoBinding.

Example usage:

class MyState with RtContextMixin, RtStateBase<MyState> {
  int _value = 0;
  int get value => value;
  set value(int n) {
    if (n == _value) return;
    update(() => _value = n);
  }
}

final state = Rt.createState<MyState>(() => MyState());

Returns the created state.

Implementation

T createState<T extends S>(T Function() buildState) {
  return BindingZone.autoBinding(buildState);
}