toJsonMap method

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

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.


Map<String, Object> toJsonMap(DiagnosticsSerializationDelegate delegate) {
  final T v = value;
  List<Map<String, Object>> properties;
  if (delegate.expandPropertyValues && delegate.includeProperties && v is Diagnosticable && getProperties().isEmpty) {
    // Exclude children for expanded nodes to avoid cycles.
    delegate = delegate.copyWith(subtreeDepth: 0, includeProperties: false);
    properties = DiagnosticsNode.toJsonList(
      delegate.filterProperties(v.toDiagnosticsNode().getProperties(), this),
  final Map<String, Object> json = super.toJsonMap(delegate);
  if (properties != null) {
    json['properties'] = properties;
  if (defaultValue != kNoDefaultValue)
    json['defaultValue'] = defaultValue.toString();
  if (ifEmpty != null)
    json['ifEmpty'] = ifEmpty;
  if (ifNull != null)
    json['ifNull'] = ifNull;
  if (tooltip != null)
    json['tooltip'] = tooltip;
  json['missingIfNull'] = missingIfNull;
  if (exception != null)
    json['exception'] = exception.toString();
  json['propertyType'] = propertyType.toString();
  json['defaultLevel'] = describeEnum(_defaultLevel);
  if (value is Diagnosticable || value is DiagnosticsNode)
    json['isDiagnosticableValue'] = true;
  if (value is num || value is String || value is bool || value == null)
    json['value'] = value;
  return json;