rootAncestorStateOfType method

  1. @Deprecated('Use findRootAncestorStateOfType instead. ' 'This feature was deprecated after v1.12.1.')
  2. @override
State<StatefulWidget> rootAncestorStateOfType (
  1. TypeMatcher matcher
)
@Deprecated('Use findRootAncestorStateOfType instead. ' 'This feature was deprecated after v1.12.1.'), override

Returns the State object of the furthest ancestor StatefulWidget widget that matches the given TypeMatcher.

This method is deprecated. Please use findRootAncestorStateOfType instead.

Implementation

@Deprecated(
  'Use findRootAncestorStateOfType instead. '
  'This feature was deprecated after v1.12.1.'
)
@override
State rootAncestorStateOfType(TypeMatcher matcher) {
  assert(_debugCheckStateIsActiveForAncestorLookup());
  Element ancestor = _parent;
  StatefulElement statefulAncestor;
  while (ancestor != null) {
    if (ancestor is StatefulElement && matcher.check(ancestor.state))
      statefulAncestor = ancestor;
    ancestor = ancestor._parent;
  }
  return statefulAncestor?.state;
}