File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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) {
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments