widgetWithSemanticLabel method

Finder widgetWithSemanticLabel(
  1. Type widgetType,
  2. String semanticLabel, {
  3. bool skipOffstage = true,
  4. Matcher? semanticMatcher,
})

Implementation

Finder widgetWithSemanticLabel(Type widgetType, String semanticLabel,
    {bool skipOffstage = true, Matcher? semanticMatcher}) {
  final parentWidget = find.ancestor(
    of: find.bySemanticsLabel(semanticLabel, skipOffstage: skipOffstage),
    matching: find.byType(widgetType, skipOffstage: skipOffstage),
  );
  if (semanticMatcher != null) {
    final semanticWidget = find.descendant(
        of: parentWidget, matching: bySemanticsLabel(semanticLabel));
    final widgetSemantics = currentWorld.tester.getSemantics(semanticWidget);
    expect(widgetSemantics, semanticMatcher);
  }
  return parentWidget;
}