From 5b12b7467fcbbdc7351d76690ce8a8693e804179 Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Tue, 4 Jul 2023 10:12:49 -0700 Subject: [PATCH] Cleanup: stop accepting DiagnosticsNode as input from DevTools. (#129302) --- .../lib/src/widgets/widget_inspector.dart | 67 ++-- .../test/widgets/widget_inspector_test.dart | 295 ++---------------- 2 files changed, 60 insertions(+), 302 deletions(-) diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 8cb610f5a8..8d2d591543 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -1722,8 +1722,8 @@ mixin WidgetInspectorService { return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName)); } - List _getProperties(String? diagnosticsOrDiagnosticableId, String groupName) { - final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); + List _getProperties(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); if (node == null) { return const []; } @@ -1760,28 +1760,22 @@ mixin WidgetInspectorService { return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName)); } - DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticsOrDiagnosticableId) { - // TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to - // APIs that invoke this method. - // https://github.com/flutter/devtools/issues/3951 - final Object? object = toObject(diagnosticsOrDiagnosticableId); + DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticableId) { + final Object? object = toObject(diagnosticableId); return objectToDiagnosticsNode(object); } - /// If posiible, returns [DiagnosticsNode] for the object. + /// If possible, returns [DiagnosticsNode] for the object. @visibleForTesting static DiagnosticsNode? objectToDiagnosticsNode(Object? object) { - if (object is DiagnosticsNode) { - return object; - } if (object is Diagnosticable) { return object.toDiagnosticsNode(); } return null; } - List _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) { - final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); + List _getChildrenSummaryTree(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); if (node == null) { return []; } @@ -1791,17 +1785,17 @@ mixin WidgetInspectorService { } /// Returns a JSON representation of the children of the [DiagnosticsNode] - /// object that [diagnosticsOrDiagnosticableId] references providing information needed + /// object that [diagnosticableId] references providing information needed /// for the details subtree view. /// /// The details subtree shows properties inline and includes all children /// rather than a filtered set of important children. - String getChildrenDetailsSubtree(String diagnosticsOrDiagnosticableId, String groupName) { - return _safeJsonEncode(_getChildrenDetailsSubtree(diagnosticsOrDiagnosticableId, groupName)); + String getChildrenDetailsSubtree(String diagnosticableId, String groupName) { + return _safeJsonEncode(_getChildrenDetailsSubtree(diagnosticableId, groupName)); } - List _getChildrenDetailsSubtree(String? diagnosticsOrDiagnosticableId, String groupName) { - final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); + List _getChildrenDetailsSubtree(String? diagnosticableId, String groupName) { + final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId); // With this value of minDepth we only expand one extra level of important nodes. final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, includeProperties: true, service: this); return _nodesToJson(node == null ? const [] : _getChildrenFiltered(node, delegate), delegate, parent: node); @@ -1913,19 +1907,19 @@ mixin WidgetInspectorService { /// * [getChildrenDetailsSubtree], a method to get children of a node /// in the details subtree. String getDetailsSubtree( - String diagnosticsOrDiagnosticableId, + String diagnosticableId, String groupName, { int subtreeDepth = 2, }) { - return _safeJsonEncode(_getDetailsSubtree(diagnosticsOrDiagnosticableId, groupName, subtreeDepth)); + return _safeJsonEncode(_getDetailsSubtree(diagnosticableId, groupName, subtreeDepth)); } Map? _getDetailsSubtree( - String? diagnosticsOrDiagnosticableId, + String? diagnosticableId, String? groupName, int subtreeDepth, ) { - final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); + final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId); if (root == null) { return null; } @@ -1941,15 +1935,12 @@ mixin WidgetInspectorService { } /// Returns a [DiagnosticsNode] representing the currently selected [Element]. - /// - /// If the currently selected [Element] is identical to the [Element] - /// referenced by `previousSelectionId` then the previous [DiagnosticsNode] is - /// reused. - // TODO(polina-c): delete [previousSelectionId] when it is not used in DevTools - // https://github.com/flutter/devtools/issues/3951 @protected String getSelectedWidget(String? previousSelectionId, String groupName) { - return _safeJsonEncode(_getSelectedWidget(previousSelectionId, groupName)); + if (previousSelectionId != null) { + debugPrint('previousSelectionId is deprecated in API'); + } + return _safeJsonEncode(_getSelectedWidget(null, groupName)); } /// Captures an image of the current state of an [object] that is a @@ -2025,11 +2016,11 @@ mixin WidgetInspectorService { Future> _getLayoutExplorerNode( Map parameters, ) { - final String? diagnosticsOrDiagnosticableId = parameters['id']; + final String? diagnosticableId = parameters['id']; final int subtreeDepth = int.parse(parameters['subtreeDepth']!); final String? groupName = parameters['groupName']; Map? result = {}; - final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); + final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId); if (root == null) { return Future>.value({ 'result': result, @@ -2233,14 +2224,11 @@ mixin WidgetInspectorService { /// if the selected [Element] should be shown in the summary tree otherwise /// returns the first ancestor of the selected [Element] shown in the summary /// tree. - /// - /// If the currently selected [Element] is identical to the [Element] - /// referenced by `previousSelectionId` then the previous [DiagnosticsNode] is - /// reused. - // TODO(polina-c): delete paramater [previousSelectionId] when it is not used in DevTools - // https://github.com/flutter/devtools/issues/3951 - String getSelectedSummaryWidget(String previousSelectionId, String groupName) { - return _safeJsonEncode(_getSelectedSummaryWidget(previousSelectionId, groupName)); + String getSelectedSummaryWidget(String? previousSelectionId, String groupName) { + if (previousSelectionId != null) { + debugPrint('previousSelectionId is deprecated in API'); + } + return _safeJsonEncode(_getSelectedSummaryWidget(null, groupName)); } _Location? _getSelectedSummaryWidgetLocation(String? previousSelectionId) { @@ -3609,7 +3597,6 @@ class InspectorSerializationDelegate implements DiagnosticsSerializationDelegate final Map result = {}; final Object? value = node.value; if (_interactive) { - result['objectId'] = service.toId(node, groupName!); result['valueId'] = service.toId(value, groupName!); } if (summaryTree) { diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 73cef653cf..0321ea2fc6 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -882,7 +882,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(chainNode['node'], isMap); final Map jsonNode = chainNode['node']! as Map; expect(service.toObject(jsonNode['valueId']! as String), equals(element)); - expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); final List jsonChildren = chainNode['children']! as List; @@ -898,30 +897,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(jsonChildren[j], isMap); final Map childJson = jsonChildren[j]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); - expect(service.toObject(childJson['objectId']! as String), isA()); } } }); - test('WidgetInspectorService getProperties for $DiagnosticsNode', () { - // TODO(polina-c): delete this test once getChildrenDetailsSubtree stops accepting DiagnosticsNode. - // https://github.com/flutter/devtools/issues/3951 - final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); - const String group = 'group'; - service.disposeAllGroups(); - final String id = service.toId(diagnostic, group)!; - final List propertiesJson = json.decode(service.getProperties(id, group)) as List; - final List properties = diagnostic.getProperties(); - expect(properties, isNotEmpty); - expect(propertiesJson.length, equals(properties.length)); - for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i]! as Map; - expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); - } - }); - - test('WidgetInspectorService getProperties for $Diagnosticable', () { + test('WidgetInspectorService getProperties', () { const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr); const String group = 'group'; service.disposeAllGroups(); @@ -933,7 +913,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -962,7 +941,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -2108,7 +2086,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(chainNode['node'], isMap); final Map jsonNode = chainNode['node']! as Map; expect(service.toObject(jsonNode['valueId']! as String), equals(element)); - expect(service.toObject(jsonNode['objectId']! as String), isA()); expect(chainNode['children'], isList); final List jsonChildren = chainNode['children']! as List; @@ -2124,32 +2101,11 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(jsonChildren[j], isMap); final Map childJson = jsonChildren[j]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(childrenElements[j])); - expect(service.toObject(childJson['objectId']! as String), isA()); } } }); - test('ext.flutter.inspector.getProperties for $DiagnosticsNode', () async { - // TODO(polina-c): delete this test once getChildrenDetailsSubtree stops accepting DiagnosticsNode. - // https://github.com/flutter/devtools/issues/3951 - final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode(); - const String group = 'group'; - final String id = service.toId(diagnostic, group)!; - final List propertiesJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getProperties.name, - {'arg': id, 'objectGroup': group}, - ))! as List; - final List properties = diagnostic.getProperties(); - expect(properties, isNotEmpty); - expect(propertiesJson.length, equals(properties.length)); - for (int i = 0; i < propertiesJson.length; ++i) { - final Map propertyJson = propertiesJson[i]! as Map; - expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); - } - }); - - test('ext.flutter.inspector.getProperties for $Diagnosticable', () async { + test('ext.flutter.inspector.getProperties', () async { const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr); const String group = 'group'; final String id = service.toId(diagnosticable, group)!; @@ -2163,7 +2119,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -2194,7 +2149,6 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { for (int i = 0; i < propertiesJson.length; ++i) { final Map propertyJson = propertiesJson[i]! as Map; expect(service.toObject(propertyJson['valueId']! as String), equals(children[i].value)); - expect(service.toObject(propertyJson['objectId']! as String), isA()); } }); @@ -2213,26 +2167,25 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ), ); - final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final Diagnosticable diagnosticable = find.byType(Stack).evaluate().first; + final String id = service.toId(diagnosticable, group)!; final List childrenJson = (await service.testExtension( WidgetInspectorServiceExtensions.getChildrenDetailsSubtree.name, {'arg': id, 'objectGroup': group}, ))! as List; - final List children = diagnostic.getChildren(); + final List children = diagnosticable.toDiagnosticsNode().getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { final Map childJson = childrenJson[i]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); - expect(service.toObject(childJson['objectId']! as String), isA()); final List propertiesJson = childJson['properties']! as List; - final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; - final List expectedProperties = diagnosticsNode.getProperties(); + final Element element = service.toObject(childJson['valueId']! as String)! as Element; + final List expectedProperties = element.toDiagnosticsNode().getProperties(); + final Iterable propertyValues = expectedProperties.map((DiagnosticsNode e) => e.value.toString()); for (final Map propertyJson in propertiesJson.cast>()) { - final Object? property = service.toObject(propertyJson['objectId']! as String); - expect(property, isA()); - expect(expectedProperties, contains(property)); + final String property = service.toObject(propertyJson['valueId']! as String)!.toString(); + expect(propertyValues, contains(property)); } } }); @@ -2252,31 +2205,30 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { ), ), ); - final DiagnosticsNode diagnostic = find.byType(Stack).evaluate().first.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final Diagnosticable diagnosticable = find.byType(Stack).evaluate().first; + final String id = service.toId(diagnosticable, group)!; final Map subtreeJson = (await service.testExtension( WidgetInspectorServiceExtensions.getDetailsSubtree.name, {'arg': id, 'objectGroup': group}, ))! as Map; - expect(subtreeJson['objectId'], equals(id)); + expect(subtreeJson['valueId'], equals(id)); final List childrenJson = subtreeJson['children']! as List; - final List children = diagnostic.getChildren(); + final List children = diagnosticable.toDiagnosticsNode().getChildren(); expect(children.length, equals(3)); expect(childrenJson.length, equals(children.length)); for (int i = 0; i < childrenJson.length; ++i) { final Map childJson = childrenJson[i]! as Map; expect(service.toObject(childJson['valueId']! as String), equals(children[i].value)); - expect(service.toObject(childJson['objectId']! as String), isA()); final List propertiesJson = childJson['properties']! as List; for (final Map propertyJson in propertiesJson.cast>()) { expect(propertyJson, isNot(contains('children'))); } - final DiagnosticsNode diagnosticsNode = service.toObject(childJson['objectId']! as String)! as DiagnosticsNode; - final List expectedProperties = diagnosticsNode.getProperties(); + final Element element = service.toObject(childJson['valueId']! as String)! as Element; + final List expectedProperties = element.toDiagnosticsNode().getProperties(); + final Iterable propertyValues = expectedProperties.map((DiagnosticsNode e) => e.value.toString()); for (final Map propertyJson in propertiesJson.cast>()) { - final Object property = service.toObject(propertyJson['objectId']! as String)!; - expect(property, isA()); - expect(expectedProperties, contains(property)); + final String property = service.toObject(propertyJson['valueId']! as String)!.toString(); + expect(propertyValues, contains(property)); } } @@ -2301,13 +2253,12 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { a.children.add(b.toDiagnosticsNode()); b.related = a; - final DiagnosticsNode diagnostic = a.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(a, group)!; final Map subtreeJson = (await service.testExtension( WidgetInspectorServiceExtensions.getDetailsSubtree.name, {'arg': id, 'objectGroup': group}, ))! as Map; - expect(subtreeJson['objectId'], equals(id)); + expect(subtreeJson['valueId'], equals(id)); expect(subtreeJson, contains('children')); final List propertiesJson = subtreeJson['properties']! as List; expect(propertiesJson.length, equals(1)); @@ -2330,118 +2281,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(nestedRelatedProperty, isNot(contains('children'))); }); - testWidgets('ext.flutter.inspector.getRootWidgetSummaryTree on $DiagnosticsNode', (WidgetTester tester) async { - // TODO(polina-c): delete this test once getChildrenSummaryTree stops accepting DiagnosticsNode. - // https://github.com/flutter/devtools/issues/3951 - const String group = 'test-group'; - - await tester.pumpWidget( - const Directionality( - textDirection: TextDirection.ltr, - child: Stack( - children: [ - Text('a', textDirection: TextDirection.ltr), - Text('b', textDirection: TextDirection.ltr), - Text('c', textDirection: TextDirection.ltr), - ], - ), - ), - ); - final Element elementA = find.text('a').evaluate().first; - - service.disposeAllGroups(); - service.resetPubRootDirectories(); - service.setSelection(elementA, 'my-group'); - final Map jsonA = (await service.testExtension( - WidgetInspectorServiceExtensions.getSelectedWidget.name, - {'objectGroup': 'my-group'}, - ))! as Map; - - service.resetPubRootDirectories(); - Map rootJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, - {'objectGroup': group}, - ))! as Map; - // We haven't yet properly specified which directories are summary tree - // directories so we get an empty tree other than the root that is always - // included. - final Object? rootWidget = service.toObject(rootJson['valueId']! as String); - expect(rootWidget, equals(WidgetsBinding.instance.rootElement)); - List childrenJson = rootJson['children']! as List; - // There are no summary tree children. - expect(childrenJson.length, equals(0)); - - final Map creationLocation = jsonA['creationLocation']! as Map; - expect(creationLocation, isNotNull); - final String testFile = creationLocation['file']! as String; - expect(testFile, endsWith('widget_inspector_test.dart')); - final List segments = Uri.parse(testFile).pathSegments; - // Strip a couple subdirectories away to generate a plausible pub root - // directory. - final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; - service.resetPubRootDirectories(); - await service.testExtension( - WidgetInspectorServiceExtensions.addPubRootDirectories.name, - {'arg0': pubRootTest}, - ); - - rootJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getRootWidgetSummaryTree.name, - {'objectGroup': group}, - ))! as Map; - childrenJson = rootJson['children']! as List; - // The tree of nodes returned contains all widgets created directly by the - // test. - childrenJson = rootJson['children']! as List; - expect(childrenJson.length, equals(1)); - - List alternateChildrenJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': rootJson['objectId']! as String, 'objectGroup': group}, - ))! as List; - expect(alternateChildrenJson.length, equals(1)); - Map childJson = childrenJson[0]! as Map; - Map alternateChildJson = alternateChildrenJson[0]! as Map; - expect(childJson['description'], startsWith('Directionality')); - expect(alternateChildJson['description'], startsWith('Directionality')); - expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - - childrenJson = childJson['children']! as List; - alternateChildrenJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': childJson['objectId']! as String, 'objectGroup': group}, - ))! as List; - expect(alternateChildrenJson.length, equals(1)); - expect(childrenJson.length, equals(1)); - alternateChildJson = alternateChildrenJson[0]! as Map; - childJson = childrenJson[0]! as Map; - expect(childJson['description'], startsWith('Stack')); - expect(alternateChildJson['description'], startsWith('Stack')); - expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - childrenJson = childJson['children']! as List; - - childrenJson = childJson['children']! as List; - alternateChildrenJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': childJson['objectId']! as String, 'objectGroup': group}, - ))! as List; - expect(alternateChildrenJson.length, equals(3)); - expect(childrenJson.length, equals(3)); - alternateChildJson = alternateChildrenJson[2]! as Map; - childJson = childrenJson[2]! as Map; - expect(childJson['description'], startsWith('Text')); - expect(alternateChildJson['description'], startsWith('Text')); - expect(alternateChildJson['valueId'], equals(childJson['valueId'])); - alternateChildrenJson = (await service.testExtension( - WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': childJson['objectId']! as String, 'objectGroup': group}, - ))! as List; - expect(alternateChildrenJson.length , equals(0)); - // Tests are failing when this typo is fixed. - expect(childJson['chidlren'], isNull); - }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. - - testWidgets('ext.flutter.inspector.getRootWidgetSummaryTree on $Diagnosticable', (WidgetTester tester) async { + testWidgets('ext.flutter.inspector.getRootWidgetSummaryTree', (WidgetTester tester) async { const String group = 'test-group'; await tester.pumpWidget( @@ -2602,7 +2442,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { List alternateChildrenJson = (await service.testExtension( WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': rootJson['objectId']! as String, 'objectGroup': group}, + {'arg': rootJson['valueId']! as String, 'objectGroup': group}, ))! as List; expect(alternateChildrenJson.length, equals(1)); Map childJson = childrenJson[0]! as Map; @@ -2614,7 +2454,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { childrenJson = childJson['children']! as List; alternateChildrenJson = (await service.testExtension( WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': childJson['objectId']! as String, 'objectGroup': group}, + {'arg': childJson['valueId']! as String, 'objectGroup': group}, ))! as List; expect(alternateChildrenJson.length, equals(1)); expect(childrenJson.length, equals(1)); @@ -2628,7 +2468,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { childrenJson = childJson['children']! as List; alternateChildrenJson = (await service.testExtension( WidgetInspectorServiceExtensions.getChildrenSummaryTree.name, - {'arg': childJson['objectId']! as String, 'objectGroup': group}, + {'arg': childJson['valueId']! as String, 'objectGroup': group}, ))! as List; expect(alternateChildrenJson.length, equals(3)); expect(childrenJson.length, equals(3)); @@ -4535,8 +4375,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element rowElement = tester.element(find.byType(Row)); service.setSelection(rowElement, group); - final DiagnosticsNode diagnostic = rowElement.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(rowElement, group)!; final Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -4581,8 +4420,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element flexibleElement = tester.element(find.byType(Flexible).first); service.setSelection(flexibleElement, group); - final DiagnosticsNode diagnostic = flexibleElement.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(flexibleElement, group)!; final Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -4623,16 +4461,14 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { await pumpWidgetForLayoutExplorer(tester); final Element element = tester.element(find.byType(Directionality).first); - Element? root; + late Element root; element.visitAncestorElements((Element ancestor) { root = ancestor; return true; }); - expect(root, isNotNull); service.setSelection(root, group); - final DiagnosticsNode diagnostic = root!.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(root, group)!; final Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -4663,8 +4499,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element childElement = tester.element(find.byType(Flexible).first); service.setSelection(childElement, group); - final DiagnosticsNode diagnostic = childElement.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(childElement, group)!; Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -4694,8 +4529,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element childElement = tester.element(find.byType(Flexible).first); service.setSelection(childElement, group); - final DiagnosticsNode diagnostic = childElement.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(childElement, group)!; Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -4725,8 +4559,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { final Element rowElement = tester.element(find.byType(Row).first); service.setSelection(rowElement, group); - final DiagnosticsNode diagnostic = rowElement.toDiagnosticsNode(); - final String id = service.toId(diagnostic, group)!; + final String id = service.toId(rowElement, group)!; Map result = (await service.testExtension( WidgetInspectorServiceExtensions.getLayoutExplorerNode.name, {'id': id, 'groupName': group, 'subtreeDepth': '1'}, @@ -5098,69 +4931,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(box2.localToGlobal(Offset.zero), equals(position2)); }); - testWidgets('getChildrenDetailsSubtree with $DiagnosticsNode', (WidgetTester tester) async { - // TODO(polina-c): delete this test once getChildrenDetailsSubtree stops accepting DiagnosticsNode. - // https://github.com/flutter/devtools/issues/3951 - await tester.pumpWidget( - MaterialApp( - title: 'Hello, World', - theme: ThemeData( - primarySwatch: Colors.blue, - ), - home: Scaffold( - appBar: AppBar( - title: const Text('Hello, World'), - ), - body: const Center( - child: Text('Hello, World!'), - ), - ), - ), - ); - service.setSelection(find.text('Hello, World!').evaluate().first, 'my-group'); - - // Figure out the pubRootDirectory - final Map jsonObject = (await service.testExtension( - WidgetInspectorServiceExtensions.getSelectedWidget.name, - {'objectGroup': 'my-group'}, - ))! as Map; - final Map creationLocation = jsonObject['creationLocation']! as Map; - expect(creationLocation, isNotNull); - final String file = creationLocation['file']! as String; - expect(file, endsWith('widget_inspector_test.dart')); - final List segments = Uri.parse(file).pathSegments; - // Strip a couple subdirectories away to generate a plausible pub rootdirectory. - final String pubRootTest = '/${segments.take(segments.length - 2).join('/')}'; - service.resetPubRootDirectories(); - service.addPubRootDirectories([pubRootTest]); - - final String summary = service.getRootWidgetSummaryTree('foo1'); - // ignore: avoid_dynamic_calls - final List childrenOfRoot = json.decode(summary)['children'] as List; - final List childrenOfMaterialApp = (childrenOfRoot.first! as Map)['children']! as List; - final Map scaffold = childrenOfMaterialApp.first! as Map; - expect(scaffold['description'], 'Scaffold'); - final String objectId = scaffold['objectId']! as String; - final String details = service.getDetailsSubtree(objectId, 'foo2'); - // ignore: avoid_dynamic_calls - final List detailedChildren = json.decode(details)['children'] as List; - - final List> appBars = >[]; - void visitChildren(List children) { - for (final Map child in children.cast>()) { - if (child['description'] == 'AppBar') { - appBars.add(child); - } - if (child.containsKey('children')) { - visitChildren(child['children']! as List); - } - } - } - visitChildren(detailedChildren); - expect(appBars.single, isNot(contains('children'))); - }, skip: !WidgetInspectorService.instance.isWidgetCreationTracked()); // [intended] Test requires --track-widget-creation flag. - - testWidgets('getChildrenDetailsSubtree with $Diagnosticable', (WidgetTester tester) async { + testWidgets('getChildrenDetailsSubtree', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( title: 'Hello, World',