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() {
int 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;
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;
final double elevation = _elevation;
double thickness = _thickness;
Uri? linkUrl = _linkUrl;
final Set<int> customSemanticsActionIds = <int>{};
for (final CustomSemanticsAction action in _customSemanticsActions.keys) {
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (hintOverrides != null) {
if (hintOverrides!.onTapHint != null) {
final CustomSemanticsAction action = CustomSemanticsAction.overridingAction(
hint: hintOverrides!.onTapHint!,
action: SemanticsAction.tap,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (hintOverrides!.onLongPressHint != null) {
final CustomSemanticsAction action = CustomSemanticsAction.overridingAction(
hint: hintOverrides!.onLongPressHint!,
action: SemanticsAction.longPress,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
}
if (mergeAllDescendantsIntoThisNode) {
_visitDescendants((SemanticsNode node) {
assert(node.isMergedIntoParent);
flags |= 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;
}
if (attributedValue.string == '') {
attributedValue = node._attributedValue;
}
if (attributedIncreasedValue.string == '') {
attributedIncreasedValue = node._attributedIncreasedValue;
}
if (attributedDecreasedValue.string == '') {
attributedDecreasedValue = node._attributedDecreasedValue;
}
if (tooltip == '') {
tooltip = node._tooltip;
}
if (node.tags != null) {
mergedTags ??= <SemanticsTag>{};
mergedTags!.addAll(node.tags!);
}
for (final CustomSemanticsAction action in _customSemanticsActions.keys) {
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (node.hintOverrides != null) {
if (node.hintOverrides!.onTapHint != null) {
final CustomSemanticsAction action = CustomSemanticsAction.overridingAction(
hint: node.hintOverrides!.onTapHint!,
action: SemanticsAction.tap,
);
customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action));
}
if (node.hintOverrides!.onLongPressHint != null) {
final CustomSemanticsAction 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,
);
thickness = math.max(thickness, node._thickness + node._elevation);
return true;
});
}
return SemanticsData(
flags: flags,
actions: _areUserActionsBlocked ? actions & _kUnblockedUserActions : actions,
identifier: identifier,
attributedLabel: attributedLabel,
attributedValue: attributedValue,
attributedIncreasedValue: attributedIncreasedValue,
attributedDecreasedValue: attributedDecreasedValue,
attributedHint: attributedHint,
tooltip: tooltip,
textDirection: textDirection,
rect: rect,
transform: transform,
elevation: elevation,
thickness: thickness,
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,
);
}