Commit eed20996 authored by Adam Barth's avatar Adam Barth

Merge pull request #1999 from abarth/null_width_factor

Don't crash if no widthFactor is set in an unbounded context
parents 5ee721fe e4a14e56
...@@ -192,13 +192,13 @@ class RenderPositionedBox extends RenderShiftedBox { ...@@ -192,13 +192,13 @@ class RenderPositionedBox extends RenderShiftedBox {
} }
void performLayout() { void performLayout() {
final bool shrinkWrapWidth = widthFactor != null || constraints.maxWidth == double.INFINITY; final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.INFINITY;
final bool shrinkWrapHeight = heightFactor != null || constraints.maxHeight == double.INFINITY; final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.INFINITY;
if (child != null) { if (child != null) {
child.layout(constraints.loosen(), parentUsesSize: true); child.layout(constraints.loosen(), parentUsesSize: true);
size = constraints.constrain(new Size(shrinkWrapWidth ? child.size.width * _widthFactor : double.INFINITY, size = constraints.constrain(new Size(shrinkWrapWidth ? child.size.width * (_widthFactor ?? 1.0) : double.INFINITY,
shrinkWrapHeight ? child.size.height * _heightFactor : double.INFINITY)); shrinkWrapHeight ? child.size.height * (_heightFactor ?? 1.0) : double.INFINITY));
final Offset delta = size - child.size; final Offset delta = size - child.size;
final BoxParentData childParentData = child.parentData; final BoxParentData childParentData = child.parentData;
childParentData.position = delta.scale(_alignment.x, _alignment.y).toPoint(); childParentData.position = delta.scale(_alignment.x, _alignment.y).toPoint();
......
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -21,4 +22,26 @@ void main() { ...@@ -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