Merge pull request #707 from abarth/tiny_flex

RenderFlex shouldn't assert when its out of space
This commit is contained in:
Adam Barth
2015-12-03 14:41:44 -08:00
2 changed files with 44 additions and 4 deletions

View File

@@ -466,14 +466,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
case FlexDirection.horizontal:
size = constraints.constrain(new Size(_overflow, crossSize));
crossSize = size.height;
assert(size.width >= _overflow);
remainingSpace = size.width - _overflow;
remainingSpace = math.max(0.0, size.width - _overflow);
break;
case FlexDirection.vertical:
size = constraints.constrain(new Size(crossSize, _overflow));
crossSize = size.width;
assert(size.height >= _overflow);
remainingSpace = size.height - _overflow;
remainingSpace = math.max(0.0, size.height - _overflow);
break;
}
_overflow = 0.0;

View File

@@ -108,4 +108,46 @@ void main() {
expect(renderBox.size.height, equals(250.0));
});
});
test('Can layout at zero size', () {
final Key childKey = new Key('childKey');
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Center(
child: new Container(
width: 0.0,
height: 0.0,
child: new Column([
new Container(
key: childKey,
width: 100.0,
height: 100.0
)], justifyContent: FlexJustifyContent.collapse
)
)
));
RenderBox renderBox = tester.findElementByKey(childKey).renderObject;
expect(renderBox.size.width, equals(0.0));
expect(renderBox.size.height, equals(100.0));
tester.pumpWidget(new Center(
child: new Container(
width: 0.0,
height: 0.0,
child: new Row([
new Container(
key: childKey,
width: 100.0,
height: 100.0
)], justifyContent: FlexJustifyContent.collapse
)
)
));
renderBox = tester.findElementByKey(childKey).renderObject;
expect(renderBox.size.width, equals(100.0));
expect(renderBox.size.height, equals(0.0));
});
});
}