resolve static method
CanvasBox
resolve(
- Node canvas,
- BoxConstraints constraints, {
- CanvasSizing sizing = CanvasSizing.fill,
The box canvas takes in constraints under sizing.
Implementation
static CanvasBox resolve(Node canvas, BoxConstraints constraints, {CanvasSizing sizing = CanvasSizing.fill}) {
final design = designSize(canvas);
final autoScale = scaleModeOf(canvas) == ScaleMode.autoScale;
final contentHeight = sizesToContent(canvas);
final double width;
double? height;
if (sizing == CanvasSizing.fill) {
width = constraints.hasBoundedWidth ? constraints.maxWidth : design.width;
if (constraints.hasBoundedHeight) {
height = constraints.maxHeight;
} else if (autoScale) {
height = autoScaleHeight(canvas, width);
} else if (!contentHeight) {
height = design.height;
}
} else {
width = sizing == CanvasSizing.fillWidth && constraints.hasBoundedWidth
? constraints.maxWidth
: constraints.constrainWidth(design.width);
if (!contentHeight) {
height = constraints.constrainHeight(autoScale ? autoScaleHeight(canvas, width) : design.height);
}
}
// A canvas as tall as its content is at least as tall as its host
// says (the window of a page that scrolls).
final least = height == null && constraints.minHeight.isFinite ? constraints.minHeight : 0.0;
if (!autoScale || design.width <= 0) {
return CanvasBox(width: width, height: height, layoutWidth: width, layoutHeight: height, scale: 1, minHeight: least);
}
// Scaled to fit the width (up to the canvas's max width), laid out at
// its design width; the height it lays out at keeps the box's ratio.
final maxWidth = canvas.layout.constraints.maxWidth;
final shown = maxWidth == null ? width : math.min(width, maxWidth);
final scale = shown / design.width;
return CanvasBox(
width: width,
height: height,
layoutWidth: design.width,
layoutHeight: height == null ? null : math.max(design.height, height / scale),
scale: scale,
minHeight: least,
);
}