find method

Future<SemanticsNode?> find(
  1. String text, {
  2. Duration? timeout,
})

Find a node that matches the given text.

The text can be a String that can also be used as a RegExp.

Implementation

Future<SemanticsNode?> find(String text, {Duration? timeout}) async {
  var nodes = _findNodes(_semanticsOwner.rootSemanticsNode!, text);

  final end = clock.now().add(timeout ?? const Duration(seconds: 10));
  while (nodes.isEmpty) {
    await pump();
    if (clock.now().isAfter(end)) {
      return null;
    }
    nodes = _findNodes(_semanticsOwner.rootSemanticsNode!, text);
  }

  return nodes.first;
}