PageView shouldn't crash in zero-size container (#8282)
Previously, we were dividing by zero. Fixes #8281
This commit is contained in:
parent
257be181fd
commit
a8e847aba9
@ -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);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user