David PHAM-VAN

Add assert to verify that layout correctly set a box

... ... @@ -50,6 +50,7 @@ class LimitedBox extends SingleChildWidget {
if (child != null) {
child.layout(context, _limitConstraints(constraints),
parentUsesSize: true);
assert(child.box != null);
size = constraints.constrain(child.box.size);
} else {
size = _limitConstraints(constraints).constrain(PdfPoint.zero);
... ... @@ -73,6 +74,7 @@ class Padding extends SingleChildWidget {
if (child != null) {
final BoxConstraints childConstraints = constraints.deflate(padding);
child.layout(context, childConstraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
box = constraints.constrainRect(
width: child.box.width + padding.horizontal,
height: child.box.height + padding.vertical);
... ... @@ -239,6 +241,7 @@ class Align extends SingleChildWidget {
if (child != null) {
child.layout(context, constraints.loosen(), parentUsesSize: true);
assert(child.box != null);
box = constraints.constrainRect(
width: shrinkWrapWidth
... ... @@ -272,6 +275,7 @@ class ConstrainedBox extends SingleChildWidget {
if (child != null) {
child.layout(context, this.constraints.enforce(constraints),
parentUsesSize: true);
assert(child.box != null);
box = child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero,
... ... @@ -308,6 +312,7 @@ class FittedBox extends SingleChildWidget {
PdfPoint size;
if (child != null) {
child.layout(context, const BoxConstraints(), parentUsesSize: true);
assert(child.box != null);
size = constraints
.constrainSizeAndAttemptToPreserveAspectRatio(child.box.size);
} else {
... ... @@ -397,6 +402,7 @@ class AspectRatio extends SingleChildWidget {
if (child != null)
child.layout(context,
BoxConstraints.tightFor(width: box.width, height: box.height));
assert(child.box != null);
}
}
... ... @@ -420,6 +426,7 @@ class CustomPaint extends SingleChildWidget {
if (child != null) {
child.layout(context, constraints.tighten(width: size.x, height: size.y),
parentUsesSize: parentUsesSize);
assert(child.box != null);
box = child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.constrain(size));
... ...
... ... @@ -152,6 +152,7 @@ class Page {
if (child != null) {
final EdgeInsets _margin = margin;
child.layout(context, constraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
child.box = PdfRect(
_margin.left,
pageFormat.height - child.box.height - _margin.top,
... ...
... ... @@ -260,6 +260,7 @@ class Flex extends MultiChildWidget {
}
}
child.layout(context, innerConstraints, parentUsesSize: true);
assert(child.box != null);
allocatedSize += _getMainSize(child);
crossSize = math.max(crossSize, _getCrossSize(child));
}
... ... @@ -329,6 +330,7 @@ class Flex extends MultiChildWidget {
}
}
child.layout(context, innerConstraints, parentUsesSize: true);
assert(child.box != null);
final double childSize = _getMainSize(child);
assert(childSize <= maxChildExtent);
allocatedSize += childSize;
... ...
... ... @@ -138,6 +138,7 @@ class GridView extends MultiChildWidget implements SpanningWidget {
math.min(children.length,
_context.firstChild + crossAxisCount * _mainAxisCount))) {
child.layout(context, innerConstraints);
assert(child.box != null);
switch (direction) {
case Axis.vertical:
... ...
... ... @@ -143,6 +143,7 @@ class MultiPage extends Page {
final Widget headerWidget = header(context);
if (headerWidget != null) {
headerWidget.layout(context, constraints, parentUsesSize: false);
assert(headerWidget.box != null);
_paintChild(context, headerWidget, _margin.left,
offsetStart - headerWidget.box.height, pageFormat.height);
offsetStart -= headerWidget.box.height;
... ... @@ -153,6 +154,7 @@ class MultiPage extends Page {
final Widget footerWidget = footer(context);
if (footerWidget != null) {
footerWidget.layout(context, constraints, parentUsesSize: false);
assert(footerWidget.box != null);
_paintChild(context, footerWidget, _margin.left, _margin.bottom,
pageFormat.height);
offsetEnd += footerWidget.box.height;
... ... @@ -167,6 +169,7 @@ class MultiPage extends Page {
}
child.layout(context, constraints, parentUsesSize: false);
assert(child.box != null);
// What to do if the widget is too big for the page?
if (offsetStart - child.box.height < offsetEnd) {
... ... @@ -191,6 +194,7 @@ class MultiPage extends Page {
child.layout(
context, constraints.copyWith(maxHeight: offsetStart - offsetEnd),
parentUsesSize: false);
assert(child.box != null);
_paintChild(context, child, _margin.left,
offsetStart - child.box.height, pageFormat.height);
... ...
... ... @@ -100,6 +100,7 @@ class Stack extends MultiChildWidget {
hasNonPositionedChildren = true;
child.layout(context, nonPositionedConstraints, parentUsesSize: true);
assert(child.box != null);
final PdfRect childSize = child.box;
width = math.max(width, childSize.width);
... ... @@ -137,6 +138,7 @@ class Stack extends MultiChildWidget {
childConstraints.tighten(height: positioned.height);
positioned.layout(context, childConstraints, parentUsesSize: true);
assert(positioned.box != null);
double x;
if (positioned.left != null) {
... ...
... ... @@ -163,6 +163,7 @@ class Table extends Widget implements SpanningWidget {
int n = 0;
for (Widget child in row.children) {
child.layout(context, const BoxConstraints());
assert(child.box != null);
final double calculatedWidth =
child.box.width == double.infinity ? 0.0 : child.box.width;
final double childFlex = child is Expanded
... ... @@ -227,6 +228,7 @@ class Table extends Widget implements SpanningWidget {
final BoxConstraints childConstraints =
BoxConstraints.tightFor(width: _widths[n]);
child.layout(context, childConstraints);
assert(child.box != null);
child.box = PdfRect(x, totalHeight, child.box.width, child.box.height);
x += _widths[n];
lineHeight = math.max(lineHeight, child.box.height);
... ...
... ... @@ -104,6 +104,7 @@ abstract class StatelessWidget extends Widget {
if (_child != null) {
_child.layout(context, constraints, parentUsesSize: parentUsesSize);
assert(_child.box != null);
box = _child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
... ... @@ -139,6 +140,7 @@ abstract class SingleChildWidget extends Widget {
{bool parentUsesSize = false}) {
if (child != null) {
child.layout(context, constraints, parentUsesSize: parentUsesSize);
assert(child.box != null);
box = child.box;
} else {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.smallest);
... ...