getSemanticsData method
Returns a summary of the semantics for this node.
If this node has mergeAllDescendantsIntoThisNode, then the returned data includes the information from this node's descendants. Otherwise, the returned data matches the data on this node.
Implementation
SemanticsData getSemanticsData() {
SemanticsFlags flags = _flags;
// Can't use _effectiveActionsAsBits here. The filtering of action bits
// must be done after the merging the its descendants.
int actions = _actionsAsBits;
String identifier = _identifier;
Object? traversalParentIdentifier = _traversalParentIdentifier;
Object? traversalChildIdentifier = _traversalChildIdentifier;
AttributedString attributedLabel = _attributedLabel;
AttributedString attributedValue = _attributedValue;
AttributedString attributedIncreasedValue = _attributedIncreasedValue;
AttributedString attributedDecreasedValue = _attributedDecreasedValue;
AttributedString attributedHint = _attributedHint;
String tooltip = _tooltip;
TextDirection? textDirection = _textDirection;
Set<SemanticsTag>? mergedTags = tags == null ? null : Set<SemanticsTag>.of(tags!);
TextSelection? textSelection = _textSelection;
int? scrollChildCount = _scrollChildCount;
int? scrollIndex = _scrollIndex;
double? scrollPosition = _scrollPosition;
double? scrollExtentMax = _scrollExtentMax;
double? scrollExtentMin = _scrollExtentMin;
int? platformViewId = _platformViewId;
int? maxValueLength = _maxValueLength;
int? currentValueLength = _currentValueLength;
int headingLevel = _headingLevel;
Uri? linkUrl = _linkUrl;
SemanticsRole role = _role;
Set<String>? controlsNodes = _controlsNodes;
SemanticsValidationResult validationResult = _validationResult;
ui.SemanticsHitTestBehavior hitTestBehavior = _hitTestBehavior;
SemanticsInputType inputType = _inputType;
final Locale? locale = _locale;
final customSemanticsActionIds = <int>{};
String? minValue = _minValue;
String? maxValue = _maxValue;
for (final CustomSemanticsAction action in _customSemanticsActions.keys) {
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (hintOverrides != null) {
if (hintOverrides!.onTapHint != null) {
final action = CustomSemanticsAction.overridingAction(
hint: hintOverrides!.onTapHint!,
action: SemanticsAction.tap,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (hintOverrides!.onLongPressHint != null) {
final action = CustomSemanticsAction.overridingAction(
hint: hintOverrides!.onLongPressHint!,
action: SemanticsAction.longPress,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
}
if (mergeAllDescendantsIntoThisNode) {
_visitDescendants((SemanticsNode node) {
assert(node.isMergedIntoParent);
flags = flags.merge(node._flags);
actions |= node._effectiveActionsAsBits;
textDirection ??= node._textDirection;
textSelection ??= node._textSelection;
scrollChildCount ??= node._scrollChildCount;
scrollIndex ??= node._scrollIndex;
scrollPosition ??= node._scrollPosition;
scrollExtentMax ??= node._scrollExtentMax;
scrollExtentMin ??= node._scrollExtentMin;
platformViewId ??= node._platformViewId;
maxValueLength ??= node._maxValueLength;
currentValueLength ??= node._currentValueLength;
linkUrl ??= node._linkUrl;
headingLevel = _mergeHeadingLevels(
sourceLevel: node._headingLevel,
targetLevel: headingLevel,
);
if (identifier == '') {
identifier = node._identifier;
}
traversalParentIdentifier ??= node.traversalParentIdentifier;
traversalChildIdentifier ??= node.traversalChildIdentifier;
if (attributedValue.string == '') {
attributedValue = node._attributedValue;
}
if (attributedIncreasedValue.string == '') {
attributedIncreasedValue = node._attributedIncreasedValue;
}
if (attributedDecreasedValue.string == '') {
attributedDecreasedValue = node._attributedDecreasedValue;
}
if (role == SemanticsRole.none) {
role = node._role;
}
if (inputType == SemanticsInputType.none) {
inputType = node._inputType;
}
if (hitTestBehavior == ui.SemanticsHitTestBehavior.defer) {
hitTestBehavior = node._hitTestBehavior;
}
if (tooltip == '') {
tooltip = node._tooltip;
}
if (node.tags != null) {
mergedTags ??= <SemanticsTag>{};
mergedTags!.addAll(node.tags!);
}
for (final CustomSemanticsAction action in node._customSemanticsActions.keys) {
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (node.hintOverrides != null) {
if (node.hintOverrides!.onTapHint != null) {
final action = CustomSemanticsAction.overridingAction(
hint: node.hintOverrides!.onTapHint!,
action: SemanticsAction.tap,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (node.hintOverrides!.onLongPressHint != null) {
final action = CustomSemanticsAction.overridingAction(
hint: node.hintOverrides!.onLongPressHint!,
action: SemanticsAction.longPress,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
}
attributedLabel = _concatAttributedString(
thisAttributedString: attributedLabel,
thisTextDirection: textDirection,
otherAttributedString: node._attributedLabel,
otherTextDirection: node._textDirection,
);
attributedHint = _concatAttributedString(
thisAttributedString: attributedHint,
thisTextDirection: textDirection,
otherAttributedString: node._attributedHint,
otherTextDirection: node._textDirection,
);
if (controlsNodes == null) {
controlsNodes = node._controlsNodes;
} else if (node._controlsNodes != null) {
controlsNodes = <String>{...controlsNodes!, ...node._controlsNodes!};
}
minValue ??= node._minValue;
maxValue ??= node._maxValue;
if (validationResult == SemanticsValidationResult.none) {
validationResult = node._validationResult;
} else if (validationResult == SemanticsValidationResult.valid) {
// When merging nodes, invalid validation result takes precedence.
// Otherwise, validation information could be lost.
if (node._validationResult != SemanticsValidationResult.none &&
node._validationResult != SemanticsValidationResult.valid) {
validationResult = node._validationResult;
}
}
return true;
});
}
return SemanticsData(
flagsCollection: flags,
actions: _areUserActionsBlocked ? actions & _kUnblockedUserActions : actions,
identifier: identifier,
traversalParentIdentifier: traversalParentIdentifier,
traversalChildIdentifier: traversalChildIdentifier,
attributedLabel: attributedLabel,
attributedValue: attributedValue,
attributedIncreasedValue: attributedIncreasedValue,
attributedDecreasedValue: attributedDecreasedValue,
attributedHint: attributedHint,
tooltip: tooltip,
textDirection: textDirection,
rect: rect,
transform: transform,
tags: mergedTags,
textSelection: textSelection,
scrollChildCount: scrollChildCount,
scrollIndex: scrollIndex,
scrollPosition: scrollPosition,
scrollExtentMax: scrollExtentMax,
scrollExtentMin: scrollExtentMin,
platformViewId: platformViewId,
maxValueLength: maxValueLength,
currentValueLength: currentValueLength,
customSemanticsActionIds: customSemanticsActionIds.toList()..sort(),
headingLevel: headingLevel,
linkUrl: linkUrl,
role: role,
controlsNodes: controlsNodes,
validationResult: validationResult,
hitTestBehavior: hitTestBehavior,
inputType: inputType,
locale: locale,
minValue: minValue,
maxValue: maxValue,
);
}