diff --git a/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart b/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart index 482c214c27b..89d4f52405e 100644 --- a/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart +++ b/packages/devtools_app/lib/src/screens/inspector/inspector_data_models.dart @@ -96,7 +96,7 @@ List computeRenderSizes({ class LayoutProperties { LayoutProperties(this.node, {int copyLevel = 1}) : description = node.description, - size = node.size, + size = node.size!, constraints = node.constraints, isFlex = node.isFlex, flexFactor = node.flexFactor, diff --git a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_data_models.dart b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_data_models.dart index f81658f4033..87972187506 100644 --- a/packages/devtools_app/lib/src/screens/inspector_v2/inspector_data_models.dart +++ b/packages/devtools_app/lib/src/screens/inspector_v2/inspector_data_models.dart @@ -119,7 +119,7 @@ enum SizeType { class LayoutProperties { LayoutProperties(this.node, {int copyLevel = 1}) : description = node.description, - size = node.size, + size = node.size!, constraints = node.constraints, isFlex = node.isFlex, flexFactor = node.flexFactor, @@ -246,7 +246,7 @@ class LayoutProperties { if (parentElement == null) return this; final parentProperties = parentElement.computeLayoutProperties(forFlexLayout: false); - return parentProperties; + return parentProperties ?? this; } WidgetSizes? get widgetWidths => _widgetSizes(SizeType.widths); diff --git a/packages/devtools_app/lib/src/screens/inspector_v2/widget_properties/properties_view.dart b/packages/devtools_app/lib/src/screens/inspector_v2/widget_properties/properties_view.dart index 08b88444e9f..f8d826c426d 100644 --- a/packages/devtools_app/lib/src/screens/inspector_v2/widget_properties/properties_view.dart +++ b/packages/devtools_app/lib/src/screens/inspector_v2/widget_properties/properties_view.dart @@ -136,8 +136,7 @@ class _PropertiesViewState extends State { RemoteDiagnosticsNode? get selectedNode => widget.controller.selectedNode.value?.diagnostic; - bool get includeLayoutExplorer => - (selectedNode?.isBoxLayout ?? false) && widget.layoutProperties != null; + bool get includeLayoutExplorer => widget.layoutProperties != null; WidgetSizes? get widgetWidths => widget.layoutProperties?.widgetWidths; diff --git a/packages/devtools_app/lib/src/shared/diagnostics/diagnostics_node.dart b/packages/devtools_app/lib/src/shared/diagnostics/diagnostics_node.dart index 2a5a32fcd54..2e2478dec18 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/diagnostics_node.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/diagnostics_node.dart @@ -153,9 +153,12 @@ class RemoteDiagnosticsNode extends DiagnosticableTree { // [deserializeSize] expects a parameter of type Map (note the // non-nullable Object), so we need to first type check as a Map and then we // can cast to the expected type. - Size get size => deserializeSize( - (json['size'] as Map?)?.cast() ?? {}, - ); + Size? get size { + final sizeMap = json['size'] as Map?; + return sizeMap == null + ? null + : deserializeSize(sizeMap.cast()); + } bool get isLocalClass { final objectGroup = objectGroupApi; @@ -454,16 +457,17 @@ class RemoteDiagnosticsNode extends DiagnosticableTree { return json[memberName] as bool; } - LayoutProperties computeLayoutProperties({required bool forFlexLayout}) { - assert(!forFlexLayout || (forFlexLayout && isFlexLayout)); + LayoutProperties? computeLayoutProperties({required bool forFlexLayout}) { + if ((!forFlexLayout && !isBoxLayout) || (forFlexLayout && !isFlexLayout)) { + return null; + } return forFlexLayout ? FlexLayoutProperties.fromDiagnostics(this) : LayoutProperties(this); } RemoteDiagnosticsNode? layoutRootNode({required bool forFlexLayout}) { - final shouldDisplayNode = forFlexLayout ? isFlexLayout : isBoxLayout; - if (!shouldDisplayNode) return null; + if (forFlexLayout && !isFlexLayout) return null; if (forFlexLayout) { return isFlex ? this : parent; @@ -472,9 +476,9 @@ class RemoteDiagnosticsNode extends DiagnosticableTree { return this; } - // TODO(https://github.com/flutter/devtools/issues/8238): Actually determine - // whether this node has a box layout. - bool get isBoxLayout => true; + // Warning: This should only be used on a layout explorer node. A regular + // remote diagnostics node never has a "size" property. + bool get isBoxLayout => size != null; bool get isFlexLayout => isFlex || (parent?.isFlex ?? false);