Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,14 @@ class DartObjectNode extends TreeNode<DartObjectNode> {

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 &&
Expand Down
4 changes: 3 additions & 1 deletion packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -190,6 +194,7 @@ DartObjectNode buildStringVariable(String value) {
),
valueAsString: value,
valueAsStringIsTruncated: true,
length: length,
),
),
_isolateRef,
Expand Down