describeSemanticsConfiguration method

  1. @override
void describeSemanticsConfiguration(
  1. SemanticsConfiguration config
)
override

Report the semantics of this node, for example for accessibility purposes.

This method should be overridden by subclasses that have interesting semantic information.

The given SemanticsConfiguration object is mutable and should be annotated in a manner that describes the current state. No reference should be kept to that object; mutating it outside of the context of the describeSemanticsConfiguration call (for example as a result of asynchronous computation) will at best have no useful effect and at worse will cause crashes as the data will be in an inconsistent state.

The following snippet will describe the node as a button that responds to tap actions.
link
abstract class SemanticButtonRenderObject extends RenderObject {
  @override
  void describeSemanticsConfiguration(SemanticsConfiguration config) {
    super.describeSemanticsConfiguration(config);
    config
      ..onTap = _handleTap
      ..label = 'I am a button'
      ..isButton = true;
  }

  void _handleTap() {
    // Do something.
  }
}

Implementation

@override
void describeSemanticsConfiguration(SemanticsConfiguration config) {
  super.describeSemanticsConfiguration(config);
  config.isSemanticBoundary = container;
  config.explicitChildNodes = explicitChildNodes;
  config.isBlockingUserActions = blockUserActions;
  assert(
    ((_properties.scopesRoute ?? false) && explicitChildNodes) || !(_properties.scopesRoute ?? false),
    'explicitChildNodes must be set to true if scopes route is true',
  );
  assert(
    !((_properties.toggled ?? false) && (_properties.checked ?? false)),
    'A semantics node cannot be toggled and checked at the same time',
  );

  if (_properties.enabled != null) {
    config.isEnabled = _properties.enabled;
  }
  if (_properties.checked != null) {
    config.isChecked = _properties.checked;
  }
  if (_properties.mixed != null) {
    config.isCheckStateMixed = _properties.mixed;
  }
  if (_properties.toggled != null) {
    config.isToggled = _properties.toggled;
  }
  if (_properties.selected != null) {
    config.isSelected = _properties.selected!;
  }
  if (_properties.button != null) {
    config.isButton = _properties.button!;
  }
  if (_properties.expanded != null) {
    config.isExpanded = _properties.expanded;
  }
  if (_properties.link != null) {
    config.isLink = _properties.link!;
  }
  if (_properties.linkUrl != null) {
    config.linkUrl = _properties.linkUrl;
  }
  if (_properties.slider != null) {
    config.isSlider = _properties.slider!;
  }
  if (_properties.keyboardKey != null) {
    config.isKeyboardKey = _properties.keyboardKey!;
  }
  if (_properties.header != null) {
    config.isHeader = _properties.header!;
  }
  if (_properties.headingLevel != null) {
    config.headingLevel = _properties.headingLevel!;
  }
  if (_properties.textField != null) {
    config.isTextField = _properties.textField!;
  }
  if (_properties.readOnly != null) {
    config.isReadOnly = _properties.readOnly!;
  }
  if (_properties.focusable != null) {
    config.isFocusable = _properties.focusable!;
  }
  if (_properties.focused != null) {
    config.isFocused = _properties.focused!;
  }
  if (_properties.inMutuallyExclusiveGroup != null) {
    config.isInMutuallyExclusiveGroup = _properties.inMutuallyExclusiveGroup!;
  }
  if (_properties.obscured != null) {
    config.isObscured = _properties.obscured!;
  }
  if (_properties.multiline != null) {
    config.isMultiline = _properties.multiline!;
  }
  if (_properties.hidden != null) {
    config.isHidden = _properties.hidden!;
  }
  if (_properties.image != null) {
    config.isImage = _properties.image!;
  }
  if (_properties.identifier != null) {
    config.identifier = _properties.identifier!;
  }
  if (_attributedLabel != null) {
    config.attributedLabel = _attributedLabel!;
  }
  if (_attributedValue != null) {
    config.attributedValue = _attributedValue!;
  }
  if (_attributedIncreasedValue != null) {
    config.attributedIncreasedValue = _attributedIncreasedValue!;
  }
  if (_attributedDecreasedValue != null) {
    config.attributedDecreasedValue = _attributedDecreasedValue!;
  }
  if (_attributedHint != null) {
    config.attributedHint = _attributedHint!;
  }
  if (_properties.tooltip != null) {
    config.tooltip = _properties.tooltip!;
  }
  if (_properties.hintOverrides != null && _properties.hintOverrides!.isNotEmpty) {
    config.hintOverrides = _properties.hintOverrides;
  }
  if (_properties.scopesRoute != null) {
    config.scopesRoute = _properties.scopesRoute!;
  }
  if (_properties.namesRoute != null) {
    config.namesRoute = _properties.namesRoute!;
  }
  if (_properties.liveRegion != null) {
    config.liveRegion = _properties.liveRegion!;
  }
  if (_properties.maxValueLength != null) {
    config.maxValueLength = _properties.maxValueLength;
  }
  if (_properties.currentValueLength != null) {
    config.currentValueLength = _properties.currentValueLength;
  }
  if (textDirection != null) {
    config.textDirection = textDirection;
  }
  if (_properties.sortKey != null) {
    config.sortKey = _properties.sortKey;
  }
  if (_properties.tagForChildren != null) {
    config.addTagForChildren(_properties.tagForChildren!);
  }
  // Registering _perform* as action handlers instead of the user provided
  // ones to ensure that changing a user provided handler from a non-null to
  // another non-null value doesn't require a semantics update.
  if (_properties.onTap != null) {
    config.onTap = _performTap;
  }
  if (_properties.onLongPress != null) {
    config.onLongPress = _performLongPress;
  }
  if (_properties.onDismiss != null) {
    config.onDismiss = _performDismiss;
  }
  if (_properties.onScrollLeft != null) {
    config.onScrollLeft = _performScrollLeft;
  }
  if (_properties.onScrollRight != null) {
    config.onScrollRight = _performScrollRight;
  }
  if (_properties.onScrollUp != null) {
    config.onScrollUp = _performScrollUp;
  }
  if (_properties.onScrollDown != null) {
    config.onScrollDown = _performScrollDown;
  }
  if (_properties.onIncrease != null) {
    config.onIncrease = _performIncrease;
  }
  if (_properties.onDecrease != null) {
    config.onDecrease = _performDecrease;
  }
  if (_properties.onCopy != null) {
    config.onCopy = _performCopy;
  }
  if (_properties.onCut != null) {
    config.onCut = _performCut;
  }
  if (_properties.onPaste != null) {
    config.onPaste = _performPaste;
  }
  if (_properties.onMoveCursorForwardByCharacter != null) {
    config.onMoveCursorForwardByCharacter = _performMoveCursorForwardByCharacter;
  }
  if (_properties.onMoveCursorBackwardByCharacter != null) {
    config.onMoveCursorBackwardByCharacter = _performMoveCursorBackwardByCharacter;
  }
  if (_properties.onMoveCursorForwardByWord != null) {
    config.onMoveCursorForwardByWord = _performMoveCursorForwardByWord;
  }
  if (_properties.onMoveCursorBackwardByWord != null) {
    config.onMoveCursorBackwardByWord = _performMoveCursorBackwardByWord;
  }
  if (_properties.onSetSelection != null) {
    config.onSetSelection = _performSetSelection;
  }
  if (_properties.onSetText != null) {
    config.onSetText = _performSetText;
  }
  if (_properties.onDidGainAccessibilityFocus != null) {
    config.onDidGainAccessibilityFocus = _performDidGainAccessibilityFocus;
  }
  if (_properties.onDidLoseAccessibilityFocus != null) {
    config.onDidLoseAccessibilityFocus = _performDidLoseAccessibilityFocus;
  }
  if (_properties.onFocus != null) {
    config.onFocus = _performFocus;
  }
  if (_properties.customSemanticsActions != null) {
    config.customSemanticsActions = _properties.customSemanticsActions!;
  }
}