Skip to content

Commit

Permalink
Determine whether a widget has a box layout before trying to show the…
Browse files Browse the repository at this point in the history
… layout explorer (flutter#8278)
  • Loading branch information
elliette authored Sep 23, 2024
1 parent 6d6bb3b commit 34bf480
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ List<double> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ class _PropertiesViewState extends State<PropertiesView> {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ class RemoteDiagnosticsNode extends DiagnosticableTree {
// [deserializeSize] expects a parameter of type Map<String, Object> (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<String, Object>() ?? <String, Object>{},
);
Size? get size {
final sizeMap = json['size'] as Map?;
return sizeMap == null
? null
: deserializeSize(sizeMap.cast<String, Object>());
}

bool get isLocalClass {
final objectGroup = objectGroupApi;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 34bf480

Please sign in to comment.