containsSemantics function

Matcher containsSemantics({
  1. String? identifier,
  2. String? label,
  3. AttributedString? attributedLabel,
  4. String? hint,
  5. AttributedString? attributedHint,
  6. String? value,
  7. AttributedString? attributedValue,
  8. String? increasedValue,
  9. AttributedString? attributedIncreasedValue,
  10. String? decreasedValue,
  11. AttributedString? attributedDecreasedValue,
  12. String? tooltip,
  13. TextDirection? textDirection,
  14. Rect? rect,
  15. Size? size,
  16. double? elevation,
  17. double? thickness,
  18. int? platformViewId,
  19. int? maxValueLength,
  20. int? currentValueLength,
  21. bool? hasCheckedState,
  22. bool? isChecked,
  23. bool? isCheckStateMixed,
  24. bool? isSelected,
  25. bool? isButton,
  26. bool? isSlider,
  27. bool? isKeyboardKey,
  28. bool? isLink,
  29. bool? isFocused,
  30. bool? isFocusable,
  31. bool? isTextField,
  32. bool? isReadOnly,
  33. bool? hasEnabledState,
  34. bool? isEnabled,
  35. bool? isInMutuallyExclusiveGroup,
  36. bool? isHeader,
  37. bool? isObscured,
  38. bool? isMultiline,
  39. bool? namesRoute,
  40. bool? scopesRoute,
  41. bool? isHidden,
  42. bool? isImage,
  43. bool? isLiveRegion,
  44. bool? hasToggledState,
  45. bool? isToggled,
  46. bool? hasImplicitScrolling,
  47. bool? hasExpandedState,
  48. bool? isExpanded,
  49. bool? hasTapAction,
  50. bool? hasFocusAction,
  51. bool? hasLongPressAction,
  52. bool? hasScrollLeftAction,
  53. bool? hasScrollRightAction,
  54. bool? hasScrollUpAction,
  55. bool? hasScrollDownAction,
  56. bool? hasIncreaseAction,
  57. bool? hasDecreaseAction,
  58. bool? hasShowOnScreenAction,
  59. bool? hasMoveCursorForwardByCharacterAction,
  60. bool? hasMoveCursorBackwardByCharacterAction,
  61. bool? hasMoveCursorForwardByWordAction,
  62. bool? hasMoveCursorBackwardByWordAction,
  63. bool? hasSetTextAction,
  64. bool? hasSetSelectionAction,
  65. bool? hasCopyAction,
  66. bool? hasCutAction,
  67. bool? hasPasteAction,
  68. bool? hasDidGainAccessibilityFocusAction,
  69. bool? hasDidLoseAccessibilityFocusAction,
  70. bool? hasDismissAction,
  71. String? onTapHint,
  72. String? onLongPressHint,
  73. List<CustomSemanticsAction>? customActions,
  74. List<Matcher>? children,
})

Asserts that a SemanticsNode contains the specified information.

There are no default expected values, so no unspecified values will be validated.

To find a SemanticsNode directly, use CommonFinders.semantics. These methods will search the semantics tree directly and avoid the edge cases that SemanticsController.find sometimes runs into.

To retrieve the semantics data of a widget, use SemanticsController.find with a Finder that returns a single widget. Semantics must be enabled in order to use this method.

Sample code

testWidgets('containsSemantics', (WidgetTester tester) async {
  final SemanticsHandle handle = tester.ensureSemantics();
  // ...
  expect(tester.getSemantics(find.text('hello')), containsSemantics(label: 'hello'));
  handle.dispose();
});

See also:

Implementation

Matcher containsSemantics({
  String? identifier,
  String? label,
  AttributedString? attributedLabel,
  String? hint,
  AttributedString? attributedHint,
  String? value,
  AttributedString? attributedValue,
  String? increasedValue,
  AttributedString? attributedIncreasedValue,
  String? decreasedValue,
  AttributedString? attributedDecreasedValue,
  String? tooltip,
  TextDirection? textDirection,
  Rect? rect,
  Size? size,
  double? elevation,
  double? thickness,
  int? platformViewId,
  int? maxValueLength,
  int? currentValueLength,
  // Flags
  bool? hasCheckedState,
  bool? isChecked,
  bool? isCheckStateMixed,
  bool? isSelected,
  bool? isButton,
  bool? isSlider,
  bool? isKeyboardKey,
  bool? isLink,
  bool? isFocused,
  bool? isFocusable,
  bool? isTextField,
  bool? isReadOnly,
  bool? hasEnabledState,
  bool? isEnabled,
  bool? isInMutuallyExclusiveGroup,
  bool? isHeader,
  bool? isObscured,
  bool? isMultiline,
  bool? namesRoute,
  bool? scopesRoute,
  bool? isHidden,
  bool? isImage,
  bool? isLiveRegion,
  bool? hasToggledState,
  bool? isToggled,
  bool? hasImplicitScrolling,
  bool? hasExpandedState,
  bool? isExpanded,
  // Actions
  bool? hasTapAction,
  bool? hasFocusAction,
  bool? hasLongPressAction,
  bool? hasScrollLeftAction,
  bool? hasScrollRightAction,
  bool? hasScrollUpAction,
  bool? hasScrollDownAction,
  bool? hasIncreaseAction,
  bool? hasDecreaseAction,
  bool? hasShowOnScreenAction,
  bool? hasMoveCursorForwardByCharacterAction,
  bool? hasMoveCursorBackwardByCharacterAction,
  bool? hasMoveCursorForwardByWordAction,
  bool? hasMoveCursorBackwardByWordAction,
  bool? hasSetTextAction,
  bool? hasSetSelectionAction,
  bool? hasCopyAction,
  bool? hasCutAction,
  bool? hasPasteAction,
  bool? hasDidGainAccessibilityFocusAction,
  bool? hasDidLoseAccessibilityFocusAction,
  bool? hasDismissAction,
  // Custom actions and overrides
  String? onTapHint,
  String? onLongPressHint,
  List<CustomSemanticsAction>? customActions,
  List<Matcher>? children,
}) {
  return _MatchesSemanticsData(
    identifier: identifier,
    label: label,
    attributedLabel: attributedLabel,
    hint: hint,
    attributedHint: attributedHint,
    value: value,
    attributedValue: attributedValue,
    increasedValue: increasedValue,
    attributedIncreasedValue: attributedIncreasedValue,
    decreasedValue: decreasedValue,
    attributedDecreasedValue: attributedDecreasedValue,
    tooltip: tooltip,
    textDirection: textDirection,
    rect: rect,
    size: size,
    elevation: elevation,
    thickness: thickness,
    platformViewId: platformViewId,
    customActions: customActions,
    maxValueLength: maxValueLength,
    currentValueLength: currentValueLength,
    // Flags
    hasCheckedState: hasCheckedState,
    isChecked: isChecked,
    isCheckStateMixed: isCheckStateMixed,
    isSelected: isSelected,
    isButton: isButton,
    isSlider: isSlider,
    isKeyboardKey: isKeyboardKey,
    isLink: isLink,
    isFocused: isFocused,
    isFocusable: isFocusable,
    isTextField: isTextField,
    isReadOnly: isReadOnly,
    hasEnabledState: hasEnabledState,
    isEnabled: isEnabled,
    isInMutuallyExclusiveGroup: isInMutuallyExclusiveGroup,
    isHeader: isHeader,
    isObscured: isObscured,
    isMultiline: isMultiline,
    namesRoute: namesRoute,
    scopesRoute: scopesRoute,
    isHidden: isHidden,
    isImage: isImage,
    isLiveRegion: isLiveRegion,
    hasToggledState: hasToggledState,
    isToggled: isToggled,
    hasImplicitScrolling: hasImplicitScrolling,
    hasExpandedState: hasExpandedState,
    isExpanded: isExpanded,
    // Actions
    hasTapAction: hasTapAction,
    hasFocusAction: hasFocusAction,
    hasLongPressAction: hasLongPressAction,
    hasScrollLeftAction: hasScrollLeftAction,
    hasScrollRightAction: hasScrollRightAction,
    hasScrollUpAction: hasScrollUpAction,
    hasScrollDownAction: hasScrollDownAction,
    hasIncreaseAction: hasIncreaseAction,
    hasDecreaseAction: hasDecreaseAction,
    hasShowOnScreenAction: hasShowOnScreenAction,
    hasMoveCursorForwardByCharacterAction: hasMoveCursorForwardByCharacterAction,
    hasMoveCursorBackwardByCharacterAction: hasMoveCursorBackwardByCharacterAction,
    hasMoveCursorForwardByWordAction: hasMoveCursorForwardByWordAction,
    hasMoveCursorBackwardByWordAction: hasMoveCursorBackwardByWordAction,
    hasSetTextAction: hasSetTextAction,
    hasSetSelectionAction: hasSetSelectionAction,
    hasCopyAction: hasCopyAction,
    hasCutAction: hasCutAction,
    hasPasteAction: hasPasteAction,
    hasDidGainAccessibilityFocusAction: hasDidGainAccessibilityFocusAction,
    hasDidLoseAccessibilityFocusAction: hasDidLoseAccessibilityFocusAction,
    hasDismissAction: hasDismissAction,
    // Custom actions and overrides
    children: children,
    onLongPressHint: onLongPressHint,
    onTapHint: onTapHint,
  );
}