in packages/devtools_app/lib/src/inspector/layout_explorer/box/box.dart [156:294]
Widget _buildChild(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final parentProperties = this.parentProperties ??
properties; // Fall back to this node's properties if there is no parent.
final parentSize = parentProperties.size;
final offset = properties.node?.parentData ??
(BoxParentData()..offset = const Offset(0, 0));
if (properties.size == null) {
// This should happen infrequently but it is better to show an error than
// crash.
return Center(
child: Text(
'Visualizing layouts for ${properties.description} widgets is not yet supported.',
),
);
}
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
// Subtract out one pixel border on each side.
final availableHeight = constraints.maxHeight - 2;
final availableWidth = constraints.maxWidth - 2;
final minFractions = [0.2, 0.5, 0.2];
double nullOutZero(double value) => value != 0.0 ? value : null;
final widths = [
nullOutZero(offset.offset.dx),
properties.size.width,
nullOutZero(parentSize != null
? parentSize.width - (properties.size.width + offset.offset.dx)
: 0.0),
];
final heights = [
nullOutZero(offset.offset.dy),
properties.size.height,
nullOutZero(parentSize != null
? parentSize.height - (properties.size.height + offset.offset.dy)
: 0.0),
];
// 3 element array with [left padding, widget width, right padding].
final displayWidths = minFractionLayout(
availableSize: availableWidth,
sizes: widths,
minFractions: minFractions,
);
// 3 element array with [top padding, widget height, bottom padding].
final displayHeights = minFractionLayout(
availableSize: availableHeight,
sizes: heights,
minFractions: minFractions,
);
final widgetWidth = displayWidths[1];
final widgetHeight = displayHeights[1];
final safeParentSize = parentSize ?? properties.size;
return Container(
width: constraints.maxWidth,
height: constraints.maxHeight,
decoration: BoxDecoration(
border: Border.all(
color: WidgetTheme.fromName(properties.node.description).color,
),
),
child: Stack(
children: [
LayoutExplorerBackground(colorScheme: colorScheme),
// Left padding.
if (widths[0] != null)
PaddingVisualizerWidget(
RenderProperties(
axis: Axis.horizontal,
size: Size(displayWidths[0], widgetHeight),
offset: Offset(0, displayHeights[0]),
realSize: Size(widths[0], safeParentSize.height),
layoutProperties: properties,
isFreeSpace: true,
),
horizontal: true,
),
// Top padding.
if (heights[0] != null)
PaddingVisualizerWidget(
RenderProperties(
axis: Axis.horizontal,
size: Size(widgetWidth, displayHeights[0]),
offset: Offset(displayWidths[0], 0),
realSize: Size(safeParentSize.width, heights[0]),
layoutProperties: properties,
isFreeSpace: true,
),
horizontal: false,
),
// Right padding.
if (widths[2] != null)
PaddingVisualizerWidget(
RenderProperties(
axis: Axis.horizontal,
size: Size(displayWidths[2], widgetHeight),
offset: Offset(
displayWidths[0] + displayWidths[1], displayHeights[0]),
realSize: Size(widths[2], safeParentSize.height),
layoutProperties: properties,
isFreeSpace: true,
),
horizontal: true,
),
// Bottom padding.
if (heights[2] != null)
PaddingVisualizerWidget(
RenderProperties(
axis: Axis.horizontal,
size: Size(widgetWidth, displayHeights[2]),
offset: Offset(displayWidths[0],
displayHeights[0] + displayHeights[1]),
realSize: Size(safeParentSize.width, heights[2]),
layoutProperties: properties,
isFreeSpace: true,
),
horizontal: false,
),
BoxChildVisualizer(
isSelected: true,
state: this,
layoutProperties: properties,
renderProperties: RenderProperties(
axis: Axis.horizontal,
size: Size(widgetWidth, widgetHeight),
offset: Offset(displayWidths[0], displayHeights[0]),
realSize: properties.size,
layoutProperties: properties,
),
),
],
),
);
},
);
}