matchesSemantics function Null safety

Matcher matchesSemantics(
  1. {String? label,
  2. String? hint,
  3. String? value,
  4. String? increasedValue,
  5. String? decreasedValue,
  6. TextDirection? textDirection,
  7. Rect? rect,
  8. Size? size,
  9. double? elevation,
  10. double? thickness,
  11. int? platformViewId,
  12. int? maxValueLength,
  13. int? currentValueLength,
  14. bool hasCheckedState = false,
  15. bool isChecked = false,
  16. bool isSelected = false,
  17. bool isButton = false,
  18. bool isSlider = false,
  19. bool isKeyboardKey = false,
  20. bool isLink = false,
  21. bool isFocused = false,
  22. bool isFocusable = false,
  23. bool isTextField = false,
  24. bool isReadOnly = false,
  25. bool hasEnabledState = false,
  26. bool isEnabled = false,
  27. bool isInMutuallyExclusiveGroup = false,
  28. bool isHeader = false,
  29. bool isObscured = false,
  30. bool isMultiline = false,
  31. bool namesRoute = false,
  32. bool scopesRoute = false,
  33. bool isHidden = false,
  34. bool isImage = false,
  35. bool isLiveRegion = false,
  36. bool hasToggledState = false,
  37. bool isToggled = false,
  38. bool hasImplicitScrolling = false,
  39. bool hasTapAction = false,
  40. bool hasLongPressAction = false,
  41. bool hasScrollLeftAction = false,
  42. bool hasScrollRightAction = false,
  43. bool hasScrollUpAction = false,
  44. bool hasScrollDownAction = false,
  45. bool hasIncreaseAction = false,
  46. bool hasDecreaseAction = false,
  47. bool hasShowOnScreenAction = false,
  48. bool hasMoveCursorForwardByCharacterAction = false,
  49. bool hasMoveCursorBackwardByCharacterAction = false,
  50. bool hasMoveCursorForwardByWordAction = false,
  51. bool hasMoveCursorBackwardByWordAction = false,
  52. bool hasSetTextAction = false,
  53. bool hasSetSelectionAction = false,
  54. bool hasCopyAction = false,
  55. bool hasCutAction = false,
  56. bool hasPasteAction = false,
  57. bool hasDidGainAccessibilityFocusAction = false,
  58. bool hasDidLoseAccessibilityFocusAction = false,
  59. bool hasDismissAction = false,
  60. String? onTapHint,
  61. String? onLongPressHint,
  62. List<CustomSemanticsAction>? customActions,
  63. 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 retrieve the semantics data of a widget, use WidgetTester.getSemantics with a Finder that returns a single widget. Semantics must be enabled in order to use this method.

Sample code

final SemanticsHandle handle = tester.ensureSemantics();
expect(tester.getSemantics(find.text('hello')), matchesSemanticsNode(label: 'hello'));
handle.dispose();

See also:

Implementation

Matcher matchesSemantics({
  String? label,
  String? hint,
  String? value,
  String? increasedValue,
  String? decreasedValue,
  TextDirection? textDirection,
  Rect? rect,
  Size? size,
  double? elevation,
  double? thickness,
  int? platformViewId,
  int? maxValueLength,
  int? currentValueLength,
  // Flags //
  bool hasCheckedState = false,
  bool isChecked = 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,
  // 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,
}) {
  final List<SemanticsFlag> flags = <SemanticsFlag>[
    if (hasCheckedState) SemanticsFlag.hasCheckedState,
    if (isChecked) SemanticsFlag.isChecked,
    if (isSelected) SemanticsFlag.isSelected,
    if (isButton) SemanticsFlag.isButton,
    if (isSlider) SemanticsFlag.isSlider,
    if (isKeyboardKey) SemanticsFlag.isKeyboardKey,
    if (isLink) SemanticsFlag.isLink,
    if (isTextField) SemanticsFlag.isTextField,
    if (isReadOnly) SemanticsFlag.isReadOnly,
    if (isFocused) SemanticsFlag.isFocused,
    if (isFocusable) SemanticsFlag.isFocusable,
    if (hasEnabledState) SemanticsFlag.hasEnabledState,
    if (isEnabled) SemanticsFlag.isEnabled,
    if (isInMutuallyExclusiveGroup) SemanticsFlag.isInMutuallyExclusiveGroup,
    if (isHeader) SemanticsFlag.isHeader,
    if (isObscured) SemanticsFlag.isObscured,
    if (isMultiline) SemanticsFlag.isMultiline,
    if (namesRoute) SemanticsFlag.namesRoute,
    if (scopesRoute) SemanticsFlag.scopesRoute,
    if (isHidden) SemanticsFlag.isHidden,
    if (isImage) SemanticsFlag.isImage,
    if (isLiveRegion) SemanticsFlag.isLiveRegion,
    if (hasToggledState) SemanticsFlag.hasToggledState,
    if (isToggled) SemanticsFlag.isToggled,
    if (hasImplicitScrolling) SemanticsFlag.hasImplicitScrolling,
    if (isSlider) SemanticsFlag.isSlider
  ];

  final List<SemanticsAction> actions = <SemanticsAction>[
    if (hasTapAction) SemanticsAction.tap,
    if (hasLongPressAction) SemanticsAction.longPress,
    if (hasScrollLeftAction) SemanticsAction.scrollLeft,
    if (hasScrollRightAction) SemanticsAction.scrollRight,
    if (hasScrollUpAction) SemanticsAction.scrollUp,
    if (hasScrollDownAction) SemanticsAction.scrollDown,
    if (hasIncreaseAction) SemanticsAction.increase,
    if (hasDecreaseAction) SemanticsAction.decrease,
    if (hasShowOnScreenAction) SemanticsAction.showOnScreen,
    if (hasMoveCursorForwardByCharacterAction) SemanticsAction.moveCursorForwardByCharacter,
    if (hasMoveCursorBackwardByCharacterAction) SemanticsAction.moveCursorBackwardByCharacter,
    if (hasSetSelectionAction) SemanticsAction.setSelection,
    if (hasCopyAction) SemanticsAction.copy,
    if (hasCutAction) SemanticsAction.cut,
    if (hasPasteAction) SemanticsAction.paste,
    if (hasDidGainAccessibilityFocusAction) SemanticsAction.didGainAccessibilityFocus,
    if (hasDidLoseAccessibilityFocusAction) SemanticsAction.didLoseAccessibilityFocus,
    if (customActions != null && customActions.isNotEmpty) SemanticsAction.customAction,
    if (hasDismissAction) SemanticsAction.dismiss,
    if (hasMoveCursorForwardByWordAction) SemanticsAction.moveCursorForwardByWord,
    if (hasMoveCursorBackwardByWordAction) SemanticsAction.moveCursorBackwardByWord,
    if (hasSetTextAction) SemanticsAction.setText,
  ];
  SemanticsHintOverrides? hintOverrides;
  if (onTapHint != null || onLongPressHint != null)
    hintOverrides = SemanticsHintOverrides(
      onTapHint: onTapHint,
      onLongPressHint: onLongPressHint,
    );

  return _MatchesSemanticsData(
    label: label,
    hint: hint,
    value: value,
    increasedValue: increasedValue,
    decreasedValue: decreasedValue,
    actions: actions,
    flags: flags,
    textDirection: textDirection,
    rect: rect,
    size: size,
    elevation: elevation,
    thickness: thickness,
    platformViewId: platformViewId,
    customActions: customActions,
    hintOverrides: hintOverrides,
    currentValueLength: currentValueLength,
    maxValueLength: maxValueLength,
    children: children,
  );
}