diff --git a/packages/flutter/lib/src/rendering/shifted_box.dart b/packages/flutter/lib/src/rendering/shifted_box.dart index e0129a7592..d6e57770f9 100644 --- a/packages/flutter/lib/src/rendering/shifted_box.dart +++ b/packages/flutter/lib/src/rendering/shifted_box.dart @@ -484,7 +484,6 @@ class RenderPositionedBox extends RenderAligningShiftedBox { /// * [RenderSizedOverflowBox], a render object that is a specific size but /// passes its original constraints through to its child, which it allows to /// overflow. - class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { /// Creates a render object that lets its child overflow itself. RenderConstrainedOverflowBox({ @@ -584,10 +583,11 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { /// render at its "natural" size. /// /// This allows a child to render at the size it would render if it were alone -/// on an infinite canvas with no constraints. This box will then expand -/// as much as it can within its own constraints and align the child based on -/// [alignment]. If the box cannot expand enough to accommodate the entire -/// child, the child will be clipped. +/// on an infinite canvas with no constraints. This box will then attempt to +/// adopt the same size, within the limits of its own constraints. If it ends +/// up with a different size, it will align the child based on [alignment]. +/// If the box cannot expand enough to accommodate the entire child, the +/// child will be clipped. /// /// In debug mode, if the child overflows the box, a warning will be printed on /// the console, and black and yellow striped areas will appear where the @@ -595,9 +595,9 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { /// /// See also: /// -/// * [RenderConstrainedBox] renders a box which imposes constraints on its -/// child. -/// * [RenderConstrainedOverflowBox], renders a box that imposes different +/// * [RenderConstrainedBox], which renders a box which imposes constraints +/// on its child. +/// * [RenderConstrainedOverflowBox], which renders a box that imposes different /// constraints on its child than it gets from its parent, possibly allowing /// the child to overflow the parent. /// * [RenderSizedOverflowBox], a render object that is a specific size but @@ -641,40 +641,31 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow if (child != null) { // Let the child lay itself out at it's "natural" size, but if // constrainedAxis is non-null, keep any constraints on that axis. + BoxConstraints childConstraints; if (constrainedAxis != null) { switch (constrainedAxis) { case Axis.horizontal: - child.layout(new BoxConstraints( - maxWidth: constraints.maxWidth, minWidth: constraints.minWidth), - parentUsesSize: true, - ); + childConstraints = new BoxConstraints(maxWidth: constraints.maxWidth, minWidth: constraints.minWidth); break; case Axis.vertical: - child.layout(new BoxConstraints( - maxHeight: constraints.maxHeight, minHeight: constraints.minHeight), - parentUsesSize: true, - ); + childConstraints = new BoxConstraints(maxHeight: constraints.maxHeight, minHeight: constraints.minHeight); break; } } else { - child.layout(const BoxConstraints(), parentUsesSize: true); + childConstraints = const BoxConstraints(); } + child.layout(childConstraints, parentUsesSize: true); size = constraints.constrain(child.size); alignChild(); final BoxParentData childParentData = child.parentData; _overflowContainerRect = Offset.zero & size; _overflowChildRect = childParentData.offset & child.size; } else { - size = constraints.constrain(Size.zero); + size = constraints.smallest; _overflowContainerRect = Rect.zero; _overflowChildRect = Rect.zero; } - - final RelativeRect overflow = new RelativeRect.fromRect(_overflowContainerRect, _overflowChildRect); - _isOverflowing = overflow.left > 0.0 || - overflow.right > 0.0 || - overflow.top > 0.0 || - overflow.bottom > 0.0; + _isOverflowing = new RelativeRect.fromRect(_overflowContainerRect, _overflowChildRect).hasInsets; } @override diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 91b214f4a2..328299e2e9 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -77,6 +77,12 @@ class RelativeRect { /// May be negative if the bottom side of the rectangle is outside of the container. final double bottom; + /// Returns whether any of the values are greater than zero. + /// + /// This corresponds to one of the sides ([left], [top], [right], or [bottom]) having + /// some positive inset towards the center. + bool get hasInsets => left > 0.0 || top > 0.0 || right > 0.0 || bottom > 0.0; + /// Returns a new rectangle object translated by the given offset. RelativeRect shift(Offset offset) { return new RelativeRect.fromLTRB(left + offset.dx, top + offset.dy, right - offset.dx, bottom - offset.dy); diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index b812c0b360..0e124d450e 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -1775,10 +1775,11 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { /// at its "natural" size. /// /// This allows a child to render at the size it would render if it were alone -/// on an infinite canvas with no constraints. This container will then expand -/// as much as it can within its own constraints and align the child based on -/// [alignment]. If the container cannot expand enough to accommodate the -/// entire child, the child will be clipped. +/// on an infinite canvas with no constraints. This container will then attempt +/// to adopt the same size, within the limits of its own constraints. If it ends +/// up with a different size, it will align the child based on [alignment]. +/// If the box cannot expand enough to accommodate the entire child, the +/// child will be clipped. /// /// In debug mode, if the child overflows the container, a warning will be /// printed on the console, and black and yellow striped areas will appear where @@ -1786,7 +1787,9 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { /// /// See also: /// -/// * [ConstrainedBox] for a box which imposes constraints on its child. +/// * [ConstrainedBox], for a box which imposes constraints on its child. +/// * [Align], which loosens the constraints given to the child rather than +/// removing them entirely. /// * [Container], a convenience widget that combines common painting, /// positioning, and sizing widgets. /// * [OverflowBox], a widget that imposes different constraints on its child