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),
  );
  expect(parentWidget, findsOneWidget, reason: "Aucun élément $semanticLabel de type $widgetType n'a été trouvé.");

  if (semanticMatcher != null) {
    final semanticWidget = find.descendant(of: parentWidget, matching: bySemanticsLabel(semanticLabel));
    final widgetSemantics = currentWorld.tester.getSemantics(semanticWidget);
    expect(widgetSemantics, semanticMatcher,
        reason: "La sémantique de l'élément ${widgetSemantics.label} ne correspond pas à l'attendu");
  }
  return parentWidget;
}