getSemanticsData method Null safety

SemanticsData getSemanticsData()

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;
  int actions = _actionsAsBits;
  AttributedString attributedLabel = _attributedLabel;
  AttributedString attributedValue = _attributedValue;
  AttributedString attributedIncreasedValue = _attributedIncreasedValue;
  AttributedString attributedDecreasedValue = _attributedDecreasedValue;
  AttributedString attributedHint = _attributedHint;
  TextDirection? textDirection = _textDirection;
  Set<SemanticsTag>? mergedTags = tags == null ? null : Set<SemanticsTag>.from(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;
  final double elevation = _elevation;
  double thickness = _thickness;
  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._actionsAsBits;
      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;
      if (attributedValue == null || attributedValue.string == '')
        attributedValue = node._attributedValue;
      if (attributedIncreasedValue == null || attributedIncreasedValue.string == '')
        attributedIncreasedValue = node._attributedIncreasedValue;
      if (attributedDecreasedValue == null || attributedDecreasedValue.string == '')
        attributedDecreasedValue = node._attributedDecreasedValue;
      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: actions,
    attributedLabel: attributedLabel,
    attributedValue: attributedValue,
    attributedIncreasedValue: attributedIncreasedValue,
    attributedDecreasedValue: attributedDecreasedValue,
    attributedHint: attributedHint,
    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(),
  );
}