currentState property

T? get 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 => switch (_currentElement) {
  StatefulElement(:final T state) => state,
  _ => null,
};