Commit a8e847ab authored by Adam Barth's avatar Adam Barth Committed by GitHub

PageView shouldn't crash in zero-size container (#8282)

Previously, we were dividing by zero.

Fixes #8281
parent 257be181
......@@ -37,8 +37,8 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
maxExtent: itemExtent,
);
final int firstIndex = math.max(0, scrollOffset ~/ itemExtent);
final int targetLastIndex = math.max(0, (targetEndScrollOffset / itemExtent).ceil() - 1);
final int firstIndex = itemExtent > 0.0 ? math.max(0, scrollOffset ~/ itemExtent) : 0;
final int targetLastIndex = itemExtent > 0.0 ? math.max(0, (targetEndScrollOffset / itemExtent).ceil() - 1) : 0;
if (firstChild != null) {
final int oldFirstIndex = indexOf(firstChild);
......
......@@ -191,4 +191,18 @@ void main() {
expect(find.text('Arizona'), findsOneWidget);
});
testWidgets('PageView in zero-size container', (WidgetTester tester) async {
await tester.pumpWidget(new Center(
child: new SizedBox(
width: 0.0,
height: 0.0,
child: new PageView(
children: kStates.map<Widget>((String state) => new Text(state)).toList(),
),
),
));
expect(find.text('Alabama'), findsOneWidget);
});
}
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