ancestor method Null safety

Finder ancestor(
  1. {required Finder of,
  2. required Finder matching,
  3. bool matchRoot = false}
)

Finds widgets that are ancestors of the of parameter and that match the matching parameter.

Sample code

// Test if a Text widget that contains 'faded' is the
// descendant of an Opacity widget with opacity 0.5:
expect(
  tester.widget<Opacity>(
    find.ancestor(
      of: find.text('faded'),
      matching: find.byType('Opacity'),
    )
  ).opacity,
  0.5
);

If the matchRoot argument is true then the widget(s) specified by of will be matched along with the ancestors.

Implementation

Finder ancestor({
  required Finder of,
  required Finder matching,
  bool matchRoot = false,
}) {
  return _AncestorFinder(of, matching, matchRoot: matchRoot);
}