Merge pull request #1999 from abarth/null_width_factor

Don't crash if no widthFactor is set in an unbounded context
This commit is contained in:
Adam Barth 2015-11-06 14:52:12 -08:00
commit eed20996ba
2 changed files with 27 additions and 4 deletions

View File

@ -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();

View File

@ -1,3 +1,4 @@
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));
});
});
}