currentState property

T? currentState

The State for the component in the tree that currently has this global key.

The current state is null if (1) there is no component in the tree that matches this global key, (2) that component is not a StatefulComponent, or the associated State object is not a subtype of T.

Implementation

T? get currentState {
  final Element? element = _currentElement;
  if (element is StatefulElement) {
    final StatefulElement statefulElement = element;
    final State state = statefulElement.state;
    if (state is T) return state;
  }
  return null;
}