Skip to content

Commit 9690394

Browse files
authored
Update objectToDiagnosticsNode to stop failing. (#129027)
Prerequisite for flutter/devtools#5918
1 parent 3f73d2c commit 9690394

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

packages/flutter/lib/src/widgets/widget_inspector.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,17 +1764,20 @@ mixin WidgetInspectorService {
17641764
// TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to
17651765
// APIs that invoke this method.
17661766
// https://github.com/flutter/devtools/issues/3951
1767-
final Object? theObject = toObject(diagnosticsOrDiagnosticableId);
1768-
if (theObject is DiagnosticsNode) {
1769-
return theObject;
1770-
}
1771-
if (theObject is Diagnosticable) {
1772-
return theObject.toDiagnosticsNode();
1767+
final Object? object = toObject(diagnosticsOrDiagnosticableId);
1768+
return objectToDiagnosticsNode(object);
1769+
}
1770+
1771+
/// If posiible, returns [DiagnosticsNode] for the object.
1772+
@visibleForTesting
1773+
static DiagnosticsNode? objectToDiagnosticsNode(Object? object) {
1774+
if (object is DiagnosticsNode) {
1775+
return object;
17731776
}
1774-
if (theObject == null) {
1775-
return null;
1777+
if (object is Diagnosticable) {
1778+
return object.toDiagnosticsNode();
17761779
}
1777-
throw StateError('Unexpected object type ${theObject.runtimeType}.');
1780+
return null;
17781781
}
17791782

17801783
List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) {

packages/flutter/test/widgets/widget_inspector_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
261261
}
262262
});
263263

264+
test ('objectToDiagnosticsNode returns null for non-diagnosticable', () {
265+
expect(WidgetInspectorService.objectToDiagnosticsNode(Alignment.bottomCenter), isNull);
266+
});
267+
264268
testWidgets('WidgetInspector smoke test', (WidgetTester tester) async {
265269
// This is a smoke test to verify that adding the inspector doesn't crash.
266270
await tester.pumpWidget(

0 commit comments

Comments
 (0)