globalState<S> method

State<S> globalState<S>(
  1. String name
)

Returns a state provided by a GlobalStateProvider.

If no state with the given name and type S is found, an StateError is thrown. The search starts at the nearest state provider of the compoent and proceeds in direction to the root of the node hierarchy.

Implementation

State<S> globalState<S>(String name) {
  ComponentContext? ctx = this;
  while (ctx != null) {
    final state = ctx._states[name];
    if (state != null && state._global && state._type.type() == S) {
      return state as State<S>;
    }
    ctx = ctx._parent;
  }
  return throw StateError('no global state with name $name and type $S found!');
}