bySemanticsLabel method
Finds Semantics widgets matching the given label
, either by
RegExp.hasMatch or string equality.
The framework may combine semantics labels in certain scenarios, such as when multiple Text widgets are in a TextButton widget. In such a case, it may be preferable to match by regular expression. Consumers of this API must not introduce unsuitable content into the semantics tree for the purposes of testing; in particular, you should prefer matching by regular expression rather than by string if the framework has combined your semantics, and not try to force the framework to break up the semantics nodes. Breaking up the nodes would have an undesirable effect on screen readers and other accessibility services.
Sample code
expect(find.bySemanticsLabel('Back'), findsOneWidget);
If the skipOffstage
argument is true (the default), then this skips
nodes that are Offstage or that are from inactive Routes.
Implementation
Finder bySemanticsLabel(Pattern label, {bool skipOffstage = true}) {
return _bySemanticsProperty(
label,
(SemanticsNode? semantics) => semantics?.label,
skipOffstage: skipOffstage,
);
}