mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
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:
parent
64bae978f1
commit
df149c0b4b
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue