assembleSemanticsNode method

  1. @override
void assembleSemanticsNode(
  1. SemanticsNode node,
  2. SemanticsConfiguration config,
  3. Iterable<SemanticsNode> children
)
override

Assemble the SemanticsNode for this RenderObject.

If describeSemanticsConfiguration sets SemanticsConfiguration.isSemanticBoundary to true, this method is called with the node created for this RenderObject, the config to be applied to that node and the children SemanticsNodes that descendants of this RenderObject have generated.

By default, the method will annotate node with config and add the children to it.

Subclasses can override this method to add additional SemanticsNodes to the tree. If new SemanticsNodes are instantiated in this method they must be disposed in clearSemantics.

Implementation

@override
void assembleSemanticsNode(
  SemanticsNode node,
  SemanticsConfiguration config,
  Iterable<SemanticsNode> children,
) {
  _lastAppliedVersion = _tree.version;

  final activeIds = <int>{};
  final rootChildren = <SemanticsNode>[];
  var sortIndex = 0.0;

  // Children are built in artboard-root coordinates. The shared
  // transform is attached to _transformContainer below, so Flutter's
  // compositor multiplies through to descendants without us touching
  // each rect.
  for (final rootId in _tree.roots) {
    final child = _buildSemanticsSubtree(rootId, activeIds, sortIndex);
    if (child != null) {
      rootChildren.add(child);
      sortIndex += 1.0;
    }
  }

  // Dispose nodes no longer in the tree.
  final staleIds =
      _cachedNodes.keys.where((id) => !activeIds.contains(id)).toList();
  for (final id in staleIds) {
    _cachedNodes.remove(id);
  }

  final container = _transformContainer ??= SemanticsNode();
  container
    ..rect = Rect.fromLTRB(
      _artboardBounds.minX,
      _artboardBounds.minY,
      _artboardBounds.maxX,
      _artboardBounds.maxY,
    )
    ..transform = _mat2DToMatrix4(_computeViewTransform())
    ..updateWith(
      config: SemanticsConfiguration(),
      childrenInInversePaintOrder: rootChildren,
    );

  node.updateWith(
    config: config,
    childrenInInversePaintOrder: [container],
  );
}