toJsonMap method

  1. @mustCallSuper
Map<String, Object> toJsonMap (DiagnosticsSerializationDelegate delegate)
@mustCallSuper

Serialize the node to a JSON map according to the configuration provided in the DiagnosticsSerializationDelegate.

Subclasses should override if they have additional properties that are useful for the GUI tools that consume this JSON.

See also:

  • WidgetInspectorService, which forms the bridge between JSON returned by this method and interactive tree views in the Flutter IntelliJ plugin.

Implementation

@mustCallSuper
Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) {
  if (kReleaseMode) {
    return <String, Object>{};
  }
  final bool hasChildren = getChildren().isNotEmpty;
  return <String, Object>{
    'description': toDescription(),
    'type': runtimeType.toString(),
    if (name != null)
      'name': name,
    if (!showSeparator)
      'showSeparator': showSeparator,
    if (level != DiagnosticLevel.info)
      'level': describeEnum(level),
    if (showName == false)
      'showName': showName,
    if (emptyBodyDescription != null)
      'emptyBodyDescription': emptyBodyDescription,
    if (style != DiagnosticsTreeStyle.sparse)
      'style': describeEnum(style),
    if (allowTruncate)
      'allowTruncate': allowTruncate,
    if (hasChildren)
      'hasChildren': hasChildren,
    if (linePrefix?.isNotEmpty == true)
      'linePrefix': linePrefix,
    if (!allowWrap)
      'allowWrap': allowWrap,
    if (allowNameWrap)
      'allowNameWrap': allowNameWrap,
    ...delegate.additionalNodeProperties(this),
    if (delegate.includeProperties)
      'properties': toJsonList(
        delegate.filterProperties(getProperties(), this),
        this,
        delegate,
      ),
    if (delegate.subtreeDepth > 0)
      'children': toJsonList(
        delegate.filterChildren(getChildren(), this),
        this,
        delegate,
      ),
  };
}