getNodeChildren method

Future<RPCResponse> getNodeChildren(
  1. String nodeId,
  2. String groupName, {
  3. bool isSummaryTree = false,
})

Gets all children of a specific node in the diagnostic tree. nodeId is the ID of the node to get children for groupName is the name of the object group that contains the node isSummaryTree if true, returns a summarized version of the children Returns a list of all child nodes with their basic information

Implementation

Future<RPCResponse> getNodeChildren(
  final String nodeId,
  final String groupName, {
  final bool isSummaryTree = false,
}) async {
  final serviceManager = devtoolsService.serviceManager;
  if (!serviceManager.connectedState.value.connected) {
    return RPCResponse.error('Not connected to VM service');
  }

  final vmService = serviceManager.service;
  if (vmService == null) {
    return RPCResponse.error('VM service not available');
  }

  final isolateId = serviceManager.isolateManager.mainIsolate.value?.id;
  if (isolateId == null) {
    return RPCResponse.error('No main isolate available');
  }

  try {
    // Use the appropriate children extension based on isSummaryTree
    final extensionMethod =
        isSummaryTree
            ? WidgetInspectorServiceExtensions.getChildrenSummaryTree
            : WidgetInspectorServiceExtensions.getChildrenDetailsSubtree;

    final response = await vmService.callServiceExtension(
      'ext.flutter.inspector.${extensionMethod.name}',
      isolateId: isolateId,
      args: {'arg': nodeId, 'objectGroup': groupName},
    );

    if (response.json == null || response.json!['result'] == null) {
      return RPCResponse.error('Node children not available');
    }

    // Parse the children
    final List<Object?> childrenList =
        response.json!['result'] as List<Object?>;
    final children =
        childrenList.map((final child) {
          final childNode = RemoteDiagnosticsNode(
            child! as Map<String, Object?>,
            null, // objectGroupApi not needed for children viewing
            false, // not a property
            null, // parent will be set when tree is built
          );
          return {
            'id': childNode.valueRef.id,
            'description': childNode.description,
            'type': childNode.type,
            'style': childNode.style.toString(),
            'hasChildren': childNode.hasChildren,
            'widgetRuntimeType': childNode.widgetRuntimeType,
            'isStateful': childNode.isStateful,
            'isSummaryTree': childNode.isSummaryTree,
          };
        }).toList();

    return RPCResponse.successMap({'children': children});
  } catch (e, stack) {
    return RPCResponse.error('Error getting node children: $e', stack);
  }
}