findRootAncestorStateOfType<T extends State<StatefulWidget> > method
Returns the State object of the furthest ancestor StatefulWidget
widget that is an instance of the given type T
.
Implementation
@override
T? findRootAncestorStateOfType<T extends State<StatefulWidget>>() {
RenderElement? ancestor = _parent;
StatefulRenderElement? statefulAncestor;
while (ancestor != null) {
if (ancestor is StatefulRenderElement && ancestor.state is T) {
statefulAncestor = ancestor;
}
ancestor = ancestor._parent;
}
return statefulAncestor?.state as T?;
}