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
This commit is contained in:
Adam Barth 2017-02-19 14:12:57 -08:00 committed by GitHub
parent 64bae978f1
commit df149c0b4b
2 changed files with 13 additions and 1 deletions

View file

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

View file

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