diff --git a/packages/flutter/lib/src/rendering/block.dart b/packages/flutter/lib/src/rendering/block.dart index 55e970d802..fae0ab6358 100644 --- a/packages/flutter/lib/src/rendering/block.dart +++ b/packages/flutter/lib/src/rendering/block.dart @@ -164,7 +164,7 @@ class RenderBlock extends RenderBlockBase { } double getMinIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) { return _getIntrinsicCrossAxis( constraints, @@ -176,7 +176,7 @@ class RenderBlock extends RenderBlockBase { } double getMaxIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) { return _getIntrinsicCrossAxis( constraints, @@ -188,7 +188,7 @@ class RenderBlock extends RenderBlockBase { } double getMinIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) return _getIntrinsicMainAxis(constraints, constraints.constrainHeight); return _getIntrinsicCrossAxis( @@ -199,7 +199,7 @@ class RenderBlock extends RenderBlockBase { } double getMaxIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) return _getIntrinsicMainAxis(constraints, constraints.constrainHeight); return _getIntrinsicCrossAxis( @@ -367,28 +367,28 @@ class RenderBlockViewport extends RenderBlockBase { } double getMinIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) return _getIntrinsicDimension(constraints, minCrossAxisExtentCallback, constraints.constrainWidth); return constraints.constrainWidth(minExtent); } double getMaxIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (isVertical) return _getIntrinsicDimension(constraints, maxCrossAxisExtentCallback, constraints.constrainWidth); return _getIntrinsicDimension(constraints, totalExtentCallback, new BoxConstraints(minWidth: minExtent).enforce(constraints).constrainWidth); } double getMinIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (!isVertical) return _getIntrinsicDimension(constraints, minCrossAxisExtentCallback, constraints.constrainHeight); return constraints.constrainHeight(0.0); } double getMaxIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (!isVertical) return _getIntrinsicDimension(constraints, maxCrossAxisExtentCallback, constraints.constrainHeight); return _getIntrinsicDimension(constraints, totalExtentCallback, new BoxConstraints(minHeight: minExtent).enforce(constraints).constrainHeight); diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index f6f70b5605..a88840a20d 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -95,6 +95,21 @@ class BoxConstraints extends Constraints { minHeight = height != null ? height : double.INFINITY, maxHeight = height != null ? height : double.INFINITY; + /// Returns new box constraints that remove the minimum width and height requirements. + BoxConstraints copyWith({ + double minWidth, + double maxWidth, + double minHeight, + double maxHeight + }) { + return new BoxConstraints( + minWidth: minWidth ?? this.minWidth, + maxWidth: maxWidth ?? this.maxWidth, + minHeight: minHeight ?? this.minHeight, + maxHeight: maxHeight ?? this.maxHeight + ); + } + /// Returns new box constraints that are smaller by the given edge dimensions. BoxConstraints deflate(EdgeDims edges) { assert(edges != null); diff --git a/packages/flutter/lib/src/rendering/custom_layout.dart b/packages/flutter/lib/src/rendering/custom_layout.dart index 6f61bddaa7..75cc490c53 100644 --- a/packages/flutter/lib/src/rendering/custom_layout.dart +++ b/packages/flutter/lib/src/rendering/custom_layout.dart @@ -32,12 +32,32 @@ abstract class MultiChildLayoutDelegate { /// the constraints parameter. The child's size is returned. Size layoutChild(Object childId, BoxConstraints constraints) { final RenderBox child = _idToChild[childId]; - assert(child != null); assert(() { - 'A MultiChildLayoutDelegate cannot layout the same child more than once.'; - return _debugChildrenNeedingLayout.remove(child); + if (child == null) { + throw new RenderingError( + 'The $this custom multichild layout delegate tried to lay out a non-existent child:\n' + 'There is no child with the id "$childId".' + ); + } + if (!_debugChildrenNeedingLayout.remove(child)) { + throw new RenderingError( + 'The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.\n' + 'Each child must be laid out exactly once.' + ); + } + try { + assert(constraints.debugAssertIsNormalized); + } on AssertionError catch (exception) { + throw new RenderingError( + 'The $this custom multichild layout delegate provided invalid box constraints for the child with id "$childId":\n' + '$exception\n' + 'The minimum width and height must be greater than or equal to zero.\n' + 'The maximum width must be greater than or equal to the minimum width.\n' + 'The maximum height must be greater than or equal to the minimum height.' + ); + } + return true; }); - assert(constraints.isNormalized); child.layout(constraints, parentUsesSize: true); return child.size; } @@ -45,11 +65,29 @@ abstract class MultiChildLayoutDelegate { /// Specify the child's origin relative to this origin. void positionChild(Object childId, Offset offset) { final RenderBox child = _idToChild[childId]; - assert(child != null); + assert(() { + if (child == null) { + throw new RenderingError( + 'The $this custom multichild layout delegate tried to position out a non-existent child:\n' + 'There is no child with the id "$childId".' + ); + } + if (offset == null) { + throw new RenderingError( + 'The $this custom multichild layout delegate provided a null position for the child with id "$childId".' + ); + } + return true; + }); final MultiChildLayoutParentData childParentData = child.parentData; childParentData.offset = offset; } + String _debugDescribeChild(RenderBox child) { + final MultiChildLayoutParentData childParentData = child.parentData; + return '${childParentData.id}: $child'; + } + void _callPerformLayout(Size size, BoxConstraints constraints, RenderBox firstChild) { final Map previousIdToChild = _idToChild; @@ -65,7 +103,16 @@ abstract class MultiChildLayoutDelegate { RenderBox child = firstChild; while (child != null) { final MultiChildLayoutParentData childParentData = child.parentData; - assert(childParentData.id != null); + assert(() { + if (childParentData.id == null) { + throw new RenderingError( + 'The following child has no ID:\n' + ' $child\n' + 'Every child of a RenderCustomMultiChildLayoutBox must have an ID in its parent data.' + ); + } + return true; + }); _idToChild[childParentData.id] = child; assert(() { _debugChildrenNeedingLayout.add(child); @@ -75,8 +122,22 @@ abstract class MultiChildLayoutDelegate { } performLayout(size, constraints); assert(() { - 'A MultiChildLayoutDelegate needs to call layoutChild on every child.'; - return _debugChildrenNeedingLayout.isEmpty; + if (_debugChildrenNeedingLayout.isNotEmpty) { + if (_debugChildrenNeedingLayout.length > 1) { + throw new RenderingError( + 'The $this custom multichild layout delegate forgot to lay out the following children:\n' + ' ${_debugChildrenNeedingLayout.map(_debugDescribeChild).join("\n ")}\n' + 'Each child must be laid out exactly once.' + ); + } else { + throw new RenderingError( + 'The $this custom multichild layout delegate forgot to lay out the following child:\n' + ' ${_debugDescribeChild(_debugChildrenNeedingLayout.single)}\n' + 'Each child must be laid out exactly once.' + ); + } + } + return true; }); } finally { _idToChild = previousIdToChild; @@ -94,6 +155,8 @@ abstract class MultiChildLayoutDelegate { /// constraints. This method must apply layoutChild() to each child. It should /// specify the final position of each child with positionChild(). void performLayout(Size size, BoxConstraints constraints); + + String toString() => '$runtimeType'; } /// Defers the layout of multiple children to a delegate. @@ -131,7 +194,7 @@ class RenderCustomMultiChildLayoutBox extends RenderBox } Size _getSize(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return constraints.constrain(_delegate.getSize(constraints)); } diff --git a/packages/flutter/lib/src/rendering/editable_line.dart b/packages/flutter/lib/src/rendering/editable_line.dart index 4d346af84a..b124ff9828 100644 --- a/packages/flutter/lib/src/rendering/editable_line.dart +++ b/packages/flutter/lib/src/rendering/editable_line.dart @@ -132,22 +132,22 @@ class RenderEditableLine extends RenderBox { } double getMinIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return constraints.constrainWidth(0.0); } double getMaxIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return constraints.constrainWidth(0.0); } double getMinIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return constraints.constrainHeight(_preferredHeight); } double getMaxIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return constraints.constrainHeight(_preferredHeight); } @@ -183,7 +183,7 @@ class RenderEditableLine extends RenderBox { // TODO(abarth): This logic should live in TextPainter and be shared with RenderParagraph. void _layoutText(BoxConstraints constraints) { assert(constraints != null); - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (_constraintsForCurrentLayout == constraints) return; // already cached this layout _textPainter.maxWidth = constraints.maxWidth; diff --git a/packages/flutter/lib/src/rendering/flex.dart b/packages/flutter/lib/src/rendering/flex.dart index 6d314432d6..2db0510d9b 100644 --- a/packages/flutter/lib/src/rendering/flex.dart +++ b/packages/flutter/lib/src/rendering/flex.dart @@ -142,7 +142,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin { } double getMinIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _delegate.getMinIntrinsicWidth(constraints, virtualChildCount); } double getMaxIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _delegate.getMaxIntrinsicWidth(constraints, virtualChildCount); } double getMinIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _delegate.getMinIntrinsicHeight(constraints, virtualChildCount); } double getMaxIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _delegate.getMaxIntrinsicHeight(constraints, virtualChildCount); } diff --git a/packages/flutter/lib/src/rendering/image.dart b/packages/flutter/lib/src/rendering/image.dart index fbde014a2c..5b18a690a1 100644 --- a/packages/flutter/lib/src/rendering/image.dart +++ b/packages/flutter/lib/src/rendering/image.dart @@ -206,26 +206,26 @@ class RenderImage extends RenderBox { } double getMinIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (_width == null && _height == null) return constraints.constrainWidth(0.0); return _sizeForConstraints(constraints).width; } double getMaxIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _sizeForConstraints(constraints).width; } double getMinIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); if (_width == null && _height == null) return constraints.constrainHeight(0.0); return _sizeForConstraints(constraints).height; } double getMaxIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); return _sizeForConstraints(constraints).height; } diff --git a/packages/flutter/lib/src/rendering/list.dart b/packages/flutter/lib/src/rendering/list.dart index 6a34107eb3..0724e2bbe8 100644 --- a/packages/flutter/lib/src/rendering/list.dart +++ b/packages/flutter/lib/src/rendering/list.dart @@ -79,7 +79,7 @@ class RenderList extends RenderVirtualViewport { } double _getIntrinsicWidth(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); switch (scrollDirection) { case Axis.vertical: return constraints.constrainWidth(0.0); @@ -97,7 +97,7 @@ class RenderList extends RenderVirtualViewport { } double _getIntrinsicHeight(BoxConstraints constraints) { - assert(constraints.isNormalized); + assert(constraints.debugAssertIsNormalized); switch (scrollDirection) { case Axis.vertical: return constraints.constrainHeight(_preferredExtent); diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 1a8225af65..f92a4aae4b 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -740,8 +740,8 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { List descendants = []; const int maxDepth = 5; void visitor(RenderObject child) { - descendants.add('${" " * depth}$child'); depth += 1; + descendants.add('${" " * depth}$child'); if (depth < maxDepth) child.visitChildren(visitor); depth -= 1; diff --git a/packages/flutter/lib/src/rendering/overflow.dart b/packages/flutter/lib/src/rendering/overflow.dart index 3ce2e4775c..2d129c426a 100644 --- a/packages/flutter/lib/src/rendering/overflow.dart +++ b/packages/flutter/lib/src/rendering/overflow.dart @@ -29,22 +29,22 @@ class RenderSizedOverflowBox extends RenderBox with RenderObjectWithChildMixin