toJsonMap method

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

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

@override
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),
      this,
      delegate,
    );
  }
  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 (v is num)
    // Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033.
    // JSON.stringify replaces infinity and NaN with null.
    json['value'] = v.isFinite ? v :  v.toString();
  if (value is String || value is bool || value == null)
    json['value'] = value;
  return json;
}