Allow find.byTooltip to use a RegEx (#149348)
## Description This adds the ability for `find.byTooltip` to use a `RegEx` to match the tooltip. Also, adds some tests for `byTooltip`, since there weren't any. ## Tests - added tests
This commit is contained in:
@@ -365,13 +365,20 @@ class CommonFinders {
|
||||
///
|
||||
/// ```dart
|
||||
/// 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 [Route]s.
|
||||
Finder byTooltip(String message, { bool skipOffstage = true }) {
|
||||
Finder byTooltip(Pattern message, {bool skipOffstage = true}) {
|
||||
return byWidgetPredicate(
|
||||
(Widget widget) => widget is Tooltip && widget.message == message,
|
||||
(Widget widget) {
|
||||
return widget is Tooltip &&
|
||||
(message is RegExp
|
||||
? ((widget.message != null && message.hasMatch(widget.message!)) ||
|
||||
(widget.richMessage != null && message.hasMatch(widget.richMessage!.toPlainText())))
|
||||
: ((widget.message ?? widget.richMessage?.toPlainText()) == message));
|
||||
},
|
||||
skipOffstage: skipOffstage,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user