ancestorStateOfType method

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

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

This method is deprecated. Please use findAncestorStateOfType instead.

Implementation

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