findRootAncestorStateOfType<T extends State<StatefulWidget>> method Null safety

T? findRootAncestorStateOfType<T extends State<StatefulWidget>>()

Returns the State object of the furthest ancestor StatefulWidget widget that is an instance of the given type T.

Functions the same way as findAncestorStateOfType but keeps visiting subsequent ancestors until there are none of the type instance of T remaining. Then returns the last one found.

This operation is O(N) as well though N is the entire widget tree rather than a subtree.

Implementation

T? findRootAncestorStateOfType<T extends State>();