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

PageView should be able to resize from zero (#8286)

When resizing a PageView from 0x0, we weren't sure what the old page
number was because all the pages are collapsed at zero. Now we avoid the
divide by zero and default to the initialPage.

Fixes #8285
parent 64bae978
......@@ -86,7 +86,7 @@ class _PagePosition extends ScrollPosition {
final double oldViewportDimensions = this.viewportDimension;
final bool result = super.applyViewportDimension(viewportDimension);
final double oldPixels = pixels;
final double page = oldPixels == null ? initialPage.toDouble() : oldPixels / oldViewportDimensions;
final double page = (oldPixels == null || oldViewportDimensions == 0.0) ? initialPage.toDouble() : oldPixels / oldViewportDimensions;
final double newPixels = page * viewportDimension;
if (newPixels != oldPixels) {
correctPixels(newPixels);
......
......@@ -204,5 +204,17 @@ void main() {
));
expect(find.text('Alabama'), findsOneWidget);
await tester.pumpWidget(new Center(
child: new SizedBox(
width: 200.0,
height: 200.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