byTooltip method

Finder byTooltip(
  1. Pattern message, {
  2. bool skipOffstage = true,
})

Finds RawTooltip or Tooltip widgets with the given message.

Sample code

expect(find.byTooltip('Back'), findsOneWidget);
expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));

If the skipOffstage argument is true (the default), then this skips nodes that are Offstage or that are from inactive Routes.

Implementation

Finder byTooltip(Pattern message, {bool skipOffstage = true}) {
  return byWidgetPredicate((Widget widget) {
    // In cases where Tooltip.excludeFromSemantics is true, Tooltip provides
    // no semantics tooltip to RawTooltip, so its message must be checked
    // directly.
    if (widget is Tooltip && (widget.excludeFromSemantics ?? false)) {
      return (message is RegExp
          ? ((widget.message != null && message.hasMatch(widget.message!)) ||
                (widget.richMessage != null &&
                    message.hasMatch(widget.richMessage!.toPlainText())))
          : ((widget.message ?? widget.richMessage?.toPlainText()) == message));
    }
    return widget is RawTooltip &&
        (message is RegExp
            ? message.hasMatch(widget.semanticsTooltip ?? '')
            : (widget.semanticsTooltip == message));
  }, skipOffstage: skipOffstage);
}