matchesSemantics function Null safety

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

See also:

Implementation

Matcher matchesSemantics({
  String? label,
  AttributedString? attributedLabel,
  String? hint,
  AttributedString? attributedHint,
  String? value,
  AttributedString? attributedValue,
  String? increasedValue,
  AttributedString? attributedIncreasedValue,
  String? decreasedValue,
  String? tooltip,
  AttributedString? attributedDecreasedValue,
  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,
    attributedLabel: attributedLabel,
    hint: hint,
    attributedHint: attributedHint,
    value: value,
    attributedValue: attributedValue,
    increasedValue: increasedValue,
    tooltip: tooltip,
    attributedIncreasedValue: attributedIncreasedValue,
    decreasedValue: decreasedValue,
    attributedDecreasedValue: attributedDecreasedValue,
    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,
  );
}