tryEvaluate method

bool tryEvaluate()

Searches a set of candidates for those that meet the requirements set by this finder and returns whether the search found any matching candidates.

This is useful in cases where an action needs to be repeated while or until a finder has results. The results from the search can be accessed using the found property without re-executing the search.

Sample code

testWidgets('Top text loads first', (WidgetTester tester) async {
  // Assume a widget is pumped with a top and bottom loading area, with
  // the texts "Top loaded" and "Bottom loaded" when loading is complete.
  // await tester.pumpWidget(...)

  // Wait until at least one loaded widget is available
  Finder loadedFinder = find.textContaining('loaded');
  while (!loadedFinder.tryEvaluate()) {
    await tester.pump(const Duration(milliseconds: 100));
  }

  expect(loadedFinder.found, hasLength(1));
  expect(tester.widget<Text>(loadedFinder).data, contains('Top'));
});

Implementation

bool tryEvaluate() {
  evaluate();
  return found.isNotEmpty;
}