Update objectToDiagnosticsNode to stop failing. (#129027)

Prerequisite for https://github.com/flutter/devtools/pull/5918
This commit is contained in:
Polina Cherkasova 2023-06-16 12:39:54 -07:00 committed by GitHub
parent 3f73d2c484
commit 9690394772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -1764,18 +1764,21 @@ mixin WidgetInspectorService {
// TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to // TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to
// APIs that invoke this method. // APIs that invoke this method.
// https://github.com/flutter/devtools/issues/3951 // https://github.com/flutter/devtools/issues/3951
final Object? theObject = toObject(diagnosticsOrDiagnosticableId); final Object? object = toObject(diagnosticsOrDiagnosticableId);
if (theObject is DiagnosticsNode) { return objectToDiagnosticsNode(object);
return theObject;
} }
if (theObject is Diagnosticable) {
return theObject.toDiagnosticsNode(); /// If posiible, returns [DiagnosticsNode] for the object.
@visibleForTesting
static DiagnosticsNode? objectToDiagnosticsNode(Object? object) {
if (object is DiagnosticsNode) {
return object;
}
if (object is Diagnosticable) {
return object.toDiagnosticsNode();
} }
if (theObject == null) {
return null; return null;
} }
throw StateError('Unexpected object type ${theObject.runtimeType}.');
}
List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) { List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) {
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId);

View File

@ -261,6 +261,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
} }
}); });
test ('objectToDiagnosticsNode returns null for non-diagnosticable', () {
expect(WidgetInspectorService.objectToDiagnosticsNode(Alignment.bottomCenter), isNull);
});
testWidgets('WidgetInspector smoke test', (WidgetTester tester) async { testWidgets('WidgetInspector smoke test', (WidgetTester tester) async {
// This is a smoke test to verify that adding the inspector doesn't crash. // This is a smoke test to verify that adding the inspector doesn't crash.
await tester.pumpWidget( await tester.pumpWidget(