diff --git a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart index 5b0ac2a9129..e61e6a43739 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart @@ -267,8 +267,14 @@ class DartObjectNode extends TreeNode { if (isRootForReferences(ref)) return true; - if (treeInitializeComplete || children.isNotEmpty || childCount > 0) { - return children.isNotEmpty || childCount > 0; + // For a String, the VM service reports the number of code units as the + // instance length, so a non-zero [childCount] does not mean the String has + // child nodes to expand into. + final hasChildNodes = + children.isNotEmpty || + (childCount > 0 && instanceRef?.kind != InstanceKind.kString); + if (treeInitializeComplete || hasChildNodes) { + return hasChildNodes; } final diagnostic = theRef?.diagnostic; if (diagnostic != null && diff --git a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md index db139f83125..a2a660a1f3e 100644 --- a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md +++ b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md @@ -64,7 +64,9 @@ TODO: Remove this section if there are not any updates. ## Debugger updates -TODO: Remove this section if there are not any updates. +* Fixed an issue where String variables showed an expand arrow (`>`) in the + variables tree even though they cannot be expanded. + [#5377](https://github.com/flutter/devtools/issues/5377) ## Network profiler updates diff --git a/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart b/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart index 95be5046d8a..a96a43495a5 100644 --- a/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart +++ b/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart @@ -106,6 +106,44 @@ void main() { expect(str.isPartialObject, isFalse); }); + group('isExpandable', () { + test('is false for a string without a length', () { + final str = buildStringVariable('Hello there!'); + expect(str.isExpandable, isFalse); + }); + + // Regression test for https://github.com/flutter/devtools/issues/5377. + test('is false for a string with a length', () { + const value = 'Hello there!'; + final str = buildStringVariable(value, length: value.length); + expect(str.childCount, equals(value.length)); + expect(str.isPartialObject, isFalse); + expect(str.isExpandable, isFalse); + }); + + test('is false for a string after its tree is initialized', () { + const value = 'Hello there!'; + final str = buildStringVariable(value, length: value.length) + ..treeInitializeComplete = true; + expect(str.isExpandable, isFalse); + }); + + test('is false for a boolean', () { + final boolean = buildBooleanVariable(true); + expect(boolean.isExpandable, isFalse); + }); + + test('is true for a non-empty list', () { + final list = buildListVariable(length: 3); + expect(list.isExpandable, isTrue); + }); + + test('is true for a non-empty map', () { + final map = buildMapVariable(length: 3); + expect(map.isExpandable, isTrue); + }); + }); + group('toString', () { test('string variable', () { final str = buildStringVariable('Hello there!'); diff --git a/packages/devtools_app/test/test_infra/utils/variable_utils.dart b/packages/devtools_app/test/test_infra/utils/variable_utils.dart index 1515c977ff9..27a87aceff6 100644 --- a/packages/devtools_app/test/test_infra/utils/variable_utils.dart +++ b/packages/devtools_app/test/test_infra/utils/variable_utils.dart @@ -176,7 +176,11 @@ DartObjectNode buildSetGroupingVariable({ ); } -DartObjectNode buildStringVariable(String value) { +/// Builds a [DartObjectNode] for a String with the given [value]. +/// +/// The VM service reports the number of code units of a String as the +/// [InstanceRef.length], so pass [length] to mirror what a live VM sends. +DartObjectNode buildStringVariable(String value, {int? length}) { return DartObjectNode.create( BoundVariable( name: _incrementRoot(), @@ -190,6 +194,7 @@ DartObjectNode buildStringVariable(String value) { ), valueAsString: value, valueAsStringIsTruncated: true, + length: length, ), ), _isolateRef,