Commit e4a14e56 authored by Adam Barth's avatar Adam Barth

Don't crash if no widthFactor is set in an unbounded context

parent 5cf258c4
......@@ -192,13 +192,13 @@ class RenderPositionedBox extends RenderShiftedBox {
}
void performLayout() {
final bool shrinkWrapWidth = widthFactor != null || constraints.maxWidth == double.INFINITY;
final bool shrinkWrapHeight = heightFactor != null || constraints.maxHeight == double.INFINITY;
final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.INFINITY;
final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.INFINITY;
if (child != null) {
child.layout(constraints.loosen(), parentUsesSize: true);
size = constraints.constrain(new Size(shrinkWrapWidth ? child.size.width * _widthFactor : double.INFINITY,
shrinkWrapHeight ? child.size.height * _heightFactor : double.INFINITY));
size = constraints.constrain(new Size(shrinkWrapWidth ? child.size.width * (_widthFactor ?? 1.0) : double.INFINITY,
shrinkWrapHeight ? child.size.height * (_heightFactor ?? 1.0) : double.INFINITY));
final Offset delta = size - child.size;
final BoxParentData childParentData = child.parentData;
childParentData.position = delta.scale(_alignment.x, _alignment.y).toPoint();
......
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';
......@@ -21,4 +22,26 @@ void main() {
);
});
});
test('Shrink wraps in finite space', () {
testWidgets((WidgetTester tester) {
GlobalKey alignKey = new GlobalKey();
tester.pumpWidget(
new ScrollableViewport(
child: new Align(
key: alignKey,
child: new Container(
width: 10.0,
height: 10.0
),
alignment: const FractionalOffset(0.50, 0.50)
)
)
);
RenderBox box = alignKey.currentContext.findRenderObject();
expect(box.size.width, equals(800.0));
expect(box.size.height, equals(10.0));
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment