currentState property

T? get currentState

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

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

Implementation

T? get currentState => switch (_currentElement) {
  StatefulElement(:final T state) => state,
  _ => null,
};