assembleSemanticsNode method Null safety

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

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.


void assembleSemanticsNode(
  SemanticsNode node,
  SemanticsConfiguration config,
  Iterable<SemanticsNode> children,
) {
  assert(() {
    if (child == null && children.isNotEmpty) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
          '$runtimeType does not have a child widget but received a non-empty list of child SemanticsNode:\n'
    return true;

  final List<CustomPainterSemantics> backgroundSemantics = _backgroundSemanticsBuilder != null
    ? _backgroundSemanticsBuilder!(size)
    : const <CustomPainterSemantics>[];
  _backgroundSemanticsNodes = _updateSemanticsChildren(_backgroundSemanticsNodes, backgroundSemantics);

  final List<CustomPainterSemantics> foregroundSemantics = _foregroundSemanticsBuilder != null
    ? _foregroundSemanticsBuilder!(size)
    : const <CustomPainterSemantics>[];
  _foregroundSemanticsNodes = _updateSemanticsChildren(_foregroundSemanticsNodes, foregroundSemantics);

  final bool hasBackgroundSemantics = _backgroundSemanticsNodes != null && _backgroundSemanticsNodes!.isNotEmpty;
  final bool hasForegroundSemantics = _foregroundSemanticsNodes != null && _foregroundSemanticsNodes!.isNotEmpty;
  final List<SemanticsNode> finalChildren = <SemanticsNode>[
    if (hasBackgroundSemantics) ..._backgroundSemanticsNodes!,
    if (hasForegroundSemantics) ..._foregroundSemanticsNodes!,
  super.assembleSemanticsNode(node, config, finalChildren);