describeSemanticsConfiguration method
- @override
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.
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;
assert((scopesRoute == true && explicitChildNodes == true) || scopesRoute != true,
'explicitChildNodes must be set to true if scopes route is true');
assert(!(toggled == true && checked == true),
'A semantics node cannot be toggled and checked at the same time');
if (enabled != null)
config.isEnabled = enabled;
if (checked != null)
config.isChecked = checked;
if (toggled != null)
config.isToggled = toggled;
if (selected != null)
config.isSelected = selected;
if (button != null)
config.isButton = button;
if (header != null)
config.isHeader = header;
if (textField != null)
config.isTextField = textField;
if (focused != null)
config.isFocused = focused;
if (inMutuallyExclusiveGroup != null)
config.isInMutuallyExclusiveGroup = inMutuallyExclusiveGroup;
if (obscured != null)
config.isObscured = obscured;
if (hidden != null)
config.isHidden = hidden;
if (image != null)
config.isImage = image;
if (label != null)
config.label = label;
if (value != null)
config.value = value;
if (increasedValue != null)
config.increasedValue = increasedValue;
if (decreasedValue != null)
config.decreasedValue = decreasedValue;
if (hint != null)
config.hint = hint;
if (hintOverrides != null && hintOverrides.isNotEmpty)
config.hintOverrides = hintOverrides;
if (scopesRoute != null)
config.scopesRoute = scopesRoute;
if (namesRoute != null)
config.namesRoute = namesRoute;
if (liveRegion != null)
config.liveRegion = liveRegion;
if (textDirection != null)
config.textDirection = textDirection;
if (sortKey != null)
config.sortKey = sortKey;
// 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 (onTap != null)
config.onTap = _performTap;
if (onLongPress != null)
config.onLongPress = _performLongPress;
if (onDismiss != null)
config.onDismiss = _performDismiss;
if (onScrollLeft != null)
config.onScrollLeft = _performScrollLeft;
if (onScrollRight != null)
config.onScrollRight = _performScrollRight;
if (onScrollUp != null)
config.onScrollUp = _performScrollUp;
if (onScrollDown != null)
config.onScrollDown = _performScrollDown;
if (onIncrease != null)
config.onIncrease = _performIncrease;
if (onDecrease != null)
config.onDecrease = _performDecrease;
if (onCopy != null)
config.onCopy = _performCopy;
if (onCut != null)
config.onCut = _performCut;
if (onPaste != null)
config.onPaste = _performPaste;
if (onMoveCursorForwardByCharacter != null)
config.onMoveCursorForwardByCharacter = _performMoveCursorForwardByCharacter;
if (onMoveCursorBackwardByCharacter != null)
config.onMoveCursorBackwardByCharacter = _performMoveCursorBackwardByCharacter;
if (onMoveCursorForwardByWord != null)
config.onMoveCursorForwardByWord = _performMoveCursorForwardByWord;
if (onMoveCursorBackwardByWord != null)
config.onMoveCursorBackwardByWord = _performMoveCursorBackwardByWord;
if (onSetSelection != null)
config.onSetSelection = _performSetSelection;
if (onDidGainAccessibilityFocus != null)
config.onDidGainAccessibilityFocus = _performDidGainAccessibilityFocus;
if (onDidLoseAccessibilityFocus != null)
config.onDidLoseAccessibilityFocus = _performDidLoseAccessibilityFocus;
if (customSemanticsActions != null)
config.customSemanticsActions = _customSemanticsActions;
}