Update getProperties to handle Diagnosticable as input. (#128897)
This commit is contained in:
parent
e87b202160
commit
dd4a8150a8
@ -1722,9 +1722,12 @@ mixin WidgetInspectorService {
|
|||||||
return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName));
|
return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Object> _getProperties(String? diagnosticsNodeId, String groupName) {
|
List<Object> _getProperties(String? diagnosticsOrDiagnosticableId, String groupName) {
|
||||||
final DiagnosticsNode? node = toObject(diagnosticsNodeId) as DiagnosticsNode?;
|
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId);
|
||||||
return _nodesToJson(node == null ? const <DiagnosticsNode>[] : node.getProperties(), InspectorSerializationDelegate(groupName: groupName, service: this), parent: node);
|
if (node == null) {
|
||||||
|
return const <Object>[];
|
||||||
|
}
|
||||||
|
return _nodesToJson(node.getProperties(), InspectorSerializationDelegate(groupName: groupName, service: this), parent: node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a JSON representation of the children of the [DiagnosticsNode]
|
/// Returns a JSON representation of the children of the [DiagnosticsNode]
|
||||||
@ -1757,26 +1760,31 @@ mixin WidgetInspectorService {
|
|||||||
return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName));
|
return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Object> _getChildrenSummaryTree(String? diagnosticsNodeId, String groupName) {
|
DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticsOrDiagnosticableId) {
|
||||||
final Object? theObject = toObject(diagnosticsNodeId);
|
// TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to
|
||||||
final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, summaryTree: true, service: this);
|
// getChildrenSummaryTree and getProperties.
|
||||||
|
|
||||||
// TODO(polina-c): remove this, when DevTools stops sending DiagnosticsNode.
|
|
||||||
// https://github.com/flutter/devtools/issues/3951
|
// https://github.com/flutter/devtools/issues/3951
|
||||||
|
final Object? theObject = toObject(diagnosticsOrDiagnosticableId);
|
||||||
if (theObject is DiagnosticsNode) {
|
if (theObject is DiagnosticsNode) {
|
||||||
return _nodesToJson(_getChildrenFiltered(theObject, delegate), delegate, parent: theObject);
|
return theObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theObject is Diagnosticable) {
|
if (theObject is Diagnosticable) {
|
||||||
final DiagnosticsNode node = theObject.toDiagnosticsNode();
|
return theObject.toDiagnosticsNode();
|
||||||
return _nodesToJson(_getChildrenFiltered(node, delegate), delegate, parent: node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theObject == null) {
|
if (theObject == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
throw StateError('Unexpected object type ${theObject.runtimeType}.');
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) {
|
||||||
|
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId);
|
||||||
|
if (node == null) {
|
||||||
return <Object>[];
|
return <Object>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw StateError('Unexpected object type ${theObject.runtimeType}');
|
final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, summaryTree: true, service: this);
|
||||||
|
return _nodesToJson(_getChildrenFiltered(node, delegate), delegate, parent: node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a JSON representation of the children of the [DiagnosticsNode]
|
/// Returns a JSON representation of the children of the [DiagnosticsNode]
|
||||||
|
@ -899,7 +899,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('WidgetInspectorService getProperties', () {
|
test('WidgetInspectorService getProperties for $DiagnosticsNode', () {
|
||||||
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
|
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
|
||||||
const String group = 'group';
|
const String group = 'group';
|
||||||
service.disposeAllGroups();
|
service.disposeAllGroups();
|
||||||
@ -915,6 +915,22 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('WidgetInspectorService getProperties for $Diagnosticable', () {
|
||||||
|
const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr);
|
||||||
|
const String group = 'group';
|
||||||
|
service.disposeAllGroups();
|
||||||
|
final String id = service.toId(diagnosticable, group)!;
|
||||||
|
final List<Object?> propertiesJson = json.decode(service.getProperties(id, group)) as List<Object?>;
|
||||||
|
final List<DiagnosticsNode> properties = diagnosticable.toDiagnosticsNode().getProperties();
|
||||||
|
expect(properties, isNotEmpty);
|
||||||
|
expect(propertiesJson.length, equals(properties.length));
|
||||||
|
for (int i = 0; i < propertiesJson.length; ++i) {
|
||||||
|
final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>;
|
||||||
|
expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value));
|
||||||
|
expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('WidgetInspectorService getChildren', (WidgetTester tester) async {
|
testWidgets('WidgetInspectorService getChildren', (WidgetTester tester) async {
|
||||||
const String group = 'test-group';
|
const String group = 'test-group';
|
||||||
|
|
||||||
@ -2107,7 +2123,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ext.flutter.inspector.getProperties', () async {
|
test('ext.flutter.inspector.getProperties for $DiagnosticsNode', () async {
|
||||||
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
|
final DiagnosticsNode diagnostic = const Text('a', textDirection: TextDirection.ltr).toDiagnosticsNode();
|
||||||
const String group = 'group';
|
const String group = 'group';
|
||||||
final String id = service.toId(diagnostic, group)!;
|
final String id = service.toId(diagnostic, group)!;
|
||||||
@ -2125,6 +2141,24 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('ext.flutter.inspector.getProperties for $Diagnosticable', () async {
|
||||||
|
const Diagnosticable diagnosticable = Text('a', textDirection: TextDirection.ltr);
|
||||||
|
const String group = 'group';
|
||||||
|
final String id = service.toId(diagnosticable, group)!;
|
||||||
|
final List<Object?> propertiesJson = (await service.testExtension(
|
||||||
|
WidgetInspectorServiceExtensions.getProperties.name,
|
||||||
|
<String, String>{'arg': id, 'objectGroup': group},
|
||||||
|
))! as List<Object?>;
|
||||||
|
final List<DiagnosticsNode> properties = diagnosticable.toDiagnosticsNode().getProperties();
|
||||||
|
expect(properties, isNotEmpty);
|
||||||
|
expect(propertiesJson.length, equals(properties.length));
|
||||||
|
for (int i = 0; i < propertiesJson.length; ++i) {
|
||||||
|
final Map<String, Object?> propertyJson = propertiesJson[i]! as Map<String, Object?>;
|
||||||
|
expect(service.toObject(propertyJson['valueId'] as String?), equals(properties[i].value));
|
||||||
|
expect(service.toObject(propertyJson['objectId']! as String), isA<DiagnosticsNode>());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('ext.flutter.inspector.getChildren', (WidgetTester tester) async {
|
testWidgets('ext.flutter.inspector.getChildren', (WidgetTester tester) async {
|
||||||
const String group = 'test-group';
|
const String group = 'test-group';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user