matchesSemantics function

Matcher matchesSemantics(
  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 = false,
  22. bool isChecked = false,
  23. bool isCheckStateMixed = false,
  24. bool isSelected = false,
  25. bool isButton = false,
  26. bool isSlider = false,
  27. bool isKeyboardKey = false,
  28. bool isLink = false,
  29. bool isFocused = false,
  30. bool isFocusable = false,
  31. bool isTextField = false,
  32. bool isReadOnly = false,
  33. bool hasEnabledState = false,
  34. bool isEnabled = false,
  35. bool isInMutuallyExclusiveGroup = false,
  36. bool isHeader = false,
  37. bool isObscured = false,
  38. bool isMultiline = false,
  39. bool namesRoute = false,
  40. bool scopesRoute = false,
  41. bool isHidden = false,
  42. bool isImage = false,
  43. bool isLiveRegion = false,
  44. bool hasToggledState = false,
  45. bool isToggled = false,
  46. bool hasImplicitScrolling = false,
  47. bool hasExpandedState = false,
  48. bool isExpanded = false,
  49. bool hasTapAction = false,
  50. bool hasLongPressAction = false,
  51. bool hasScrollLeftAction = false,
  52. bool hasScrollRightAction = false,
  53. bool hasScrollUpAction = false,
  54. bool hasScrollDownAction = false,
  55. bool hasIncreaseAction = false,
  56. bool hasDecreaseAction = false,
  57. bool hasShowOnScreenAction = false,
  58. bool hasMoveCursorForwardByCharacterAction = false,
  59. bool hasMoveCursorBackwardByCharacterAction = false,
  60. bool hasMoveCursorForwardByWordAction = false,
  61. bool hasMoveCursorBackwardByWordAction = false,
  62. bool hasSetTextAction = false,
  63. bool hasSetSelectionAction = false,
  64. bool hasCopyAction = false,
  65. bool hasCutAction = false,
  66. bool hasPasteAction = false,
  67. bool hasDidGainAccessibilityFocusAction = false,
  68. bool hasDidLoseAccessibilityFocusAction = false,
  69. bool hasDismissAction = false,
  70. String? onTapHint,
  71. String? onLongPressHint,
  72. List<CustomSemanticsAction>? customActions,
  73. List<Matcher>? children}
)

Asserts that a SemanticsNode contains the specified information.

If either the label, hint, value, textDirection, or rect fields are not provided, then they are not part of the comparison. All of the boolean flag and action fields must match, and default to false.

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('matchesSemantics', (WidgetTester tester) async {
  final SemanticsHandle handle = tester.ensureSemantics();
  // ...
  expect(tester.getSemantics(find.text('hello')), matchesSemantics(label: 'hello'));
  handle.dispose();
});

See also:

Implementation

Matcher matchesSemantics({
  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 = false,
  bool isChecked = false,
  bool isCheckStateMixed = false,
  bool isSelected = false,
  bool isButton = false,
  bool isSlider = false,
  bool isKeyboardKey = false,
  bool isLink = false,
  bool isFocused = false,
  bool isFocusable = false,
  bool isTextField = false,
  bool isReadOnly = false,
  bool hasEnabledState = false,
  bool isEnabled = false,
  bool isInMutuallyExclusiveGroup = false,
  bool isHeader = false,
  bool isObscured = false,
  bool isMultiline = false,
  bool namesRoute = false,
  bool scopesRoute = false,
  bool isHidden = false,
  bool isImage = false,
  bool isLiveRegion = false,
  bool hasToggledState = false,
  bool isToggled = false,
  bool hasImplicitScrolling = false,
  bool hasExpandedState = false,
  bool isExpanded = false,
  // Actions //
  bool hasTapAction = false,
  bool hasLongPressAction = false,
  bool hasScrollLeftAction = false,
  bool hasScrollRightAction = false,
  bool hasScrollUpAction = false,
  bool hasScrollDownAction = false,
  bool hasIncreaseAction = false,
  bool hasDecreaseAction = false,
  bool hasShowOnScreenAction = false,
  bool hasMoveCursorForwardByCharacterAction = false,
  bool hasMoveCursorBackwardByCharacterAction = false,
  bool hasMoveCursorForwardByWordAction = false,
  bool hasMoveCursorBackwardByWordAction = false,
  bool hasSetTextAction = false,
  bool hasSetSelectionAction = false,
  bool hasCopyAction = false,
  bool hasCutAction = false,
  bool hasPasteAction = false,
  bool hasDidGainAccessibilityFocusAction = false,
  bool hasDidLoseAccessibilityFocusAction = false,
  bool hasDismissAction = false,
  // 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,
    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,
  );
}