toJsonMap method Null safety

  1. @override
Map<String, Object?> toJsonMap(
  1. 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'] =;
  if (value is Diagnosticable || value is DiagnosticsNode)
    json['isDiagnosticableValue'] = true;
  if (v is num)
    // Workaround for
    // 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;