Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update objectToDiagnosticsNode to stop failing. #129027

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/flutter/lib/src/widgets/widget_inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1764,17 +1764,20 @@ mixin WidgetInspectorService {
// 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? theObject = toObject(diagnosticsOrDiagnosticableId);
if (theObject is DiagnosticsNode) {
return theObject;
}
if (theObject is Diagnosticable) {
return theObject.toDiagnosticsNode();
final Object? object = toObject(diagnosticsOrDiagnosticableId);
return objectToDiagnosticsNode(object);
}

/// If posiible, returns [DiagnosticsNode] for the object.
@visibleForTesting
static DiagnosticsNode? objectToDiagnosticsNode(Object? object) {
if (object is DiagnosticsNode) {
return object;
}
if (theObject == null) {
return null;
if (object is Diagnosticable) {
return object.toDiagnosticsNode();
}
throw StateError('Unexpected object type ${theObject.runtimeType}.');
return null;
}

List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) {
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter/test/widgets/widget_inspector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// This is a smoke test to verify that adding the inspector doesn't crash.
await tester.pumpWidget(
Expand Down