From 72828d66cf5fbef32270e5c71c58724a14618c3f Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 13 Jun 2019 16:14:14 -0700 Subject: [PATCH] Include raw value in Diagnostics json for basic types (#34417) --- .../lib/src/foundation/diagnostics.dart | 2 + .../test/foundation/diagnostics_test.dart | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index 725ea45ac0..877e8e3ec7 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -2551,6 +2551,8 @@ class DiagnosticsProperty extends DiagnosticsNode { 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; } diff --git a/packages/flutter/test/foundation/diagnostics_test.dart b/packages/flutter/test/foundation/diagnostics_test.dart index 99bd805f44..cd321cbbbb 100644 --- a/packages/flutter/test/foundation/diagnostics_test.dart +++ b/packages/flutter/test/foundation/diagnostics_test.dart @@ -2098,4 +2098,41 @@ void main() { ) ); }); + + test('DiagnosticsProperty for basic types has value in json', () { + DiagnosticsProperty intProperty = DiagnosticsProperty('int1', 10); + Map json = simulateJsonSerialization(intProperty); + expect(json['name'], 'int1'); + expect(json['value'], 10); + + intProperty = IntProperty('int2', 20); + json = simulateJsonSerialization(intProperty); + expect(json['name'], 'int2'); + expect(json['value'], 20); + + DiagnosticsProperty doubleProperty = DiagnosticsProperty('double', 33.3); + json = simulateJsonSerialization(doubleProperty); + expect(json['name'], 'double'); + expect(json['value'], 33.3); + + doubleProperty = DoubleProperty('double2', 33.3); + json = simulateJsonSerialization(doubleProperty); + expect(json['name'], 'double2'); + expect(json['value'], 33.3); + + final DiagnosticsProperty boolProperty = DiagnosticsProperty('bool', true); + json = simulateJsonSerialization(boolProperty); + expect(json['name'], 'bool'); + expect(json['value'], true); + + DiagnosticsProperty stringProperty = DiagnosticsProperty('string1', 'hello'); + json = simulateJsonSerialization(stringProperty); + expect(json['name'], 'string1'); + expect(json['value'], 'hello'); + + stringProperty = StringProperty('string2', 'world'); + json = simulateJsonSerialization(stringProperty); + expect(json['name'], 'string2'); + expect(json['value'], 'world'); + }); }