From 8106f2ad1c4ad8e85b4481c7b9438494d61a1a4e Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:16:20 -0800 Subject: [PATCH] [Widget Inspector] Only include `truncated` field in JSON response if `true` (#159701) Work towards https://github.com/flutter/devtools/issues/8582 Follow up to https://github.com/flutter/flutter/pull/159454 Only include the `truncated` field if it is `true`. We accidentally were including it even when `false` which is what caused the regression in the DevTools tests. --- packages/flutter/lib/src/foundation/diagnostics.dart | 3 ++- packages/flutter/test/foundation/diagnostics_json_test.dart | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index 1cdb4c7fd4..30f9f417ea 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -1892,7 +1892,8 @@ abstract class DiagnosticsNode { // description instead, see: // https://github.com/flutter/devtools/issues/8556 'widgetRuntimeType': widgetRuntimeType, - 'truncated': truncated, + if (truncated) + 'truncated': truncated, ...delegate.additionalNodeProperties(this, fullDetails: false), if (includeChildren) 'children': childrenJsonList, }; diff --git a/packages/flutter/test/foundation/diagnostics_json_test.dart b/packages/flutter/test/foundation/diagnostics_json_test.dart index 67a517e3d7..ef2969a6a8 100644 --- a/packages/flutter/test/foundation/diagnostics_json_test.dart +++ b/packages/flutter/test/foundation/diagnostics_json_test.dart @@ -130,6 +130,12 @@ void main() { reason: '$keyName is not included.', ); } + + // The truncated value should not be included if it is false. + expect( + result['truncated'] == null || result['truncated'] == true, + isTrue, + ); }); test('subtreeDepth 1', () {