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

Determine whether a widget has a box layout before trying to show the layout explorer #8278

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
elliette marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading