flutter/packages/unit/test/widget/pageable_list_test.dart
Hixie 820137b7f9 Remove the inner SizeObserver from ScrollableWidgetList.
Adds a HomogeneousViewport class that works like MixedViewport but
handles only children that have all the same height.

Converts ScrollableWidgetList to use that, so that we don't waste a
frame looking at the size of the contents each time we change size.

This allows a number of seemingly pointless double-pumps in the tests
to be removed.

Other changes that were necessary to support the above:

 - RenderBlock now supports minExtent (think 'min-height' in CSS)
 - RenderBlock now supports itemExtent (forces the height of each
   child to be the same, so that the itemExtent passed to the fixed-
   height scrollables are all authoritative instead of a source of
   bugs when they don't match)
 - RenderBlockViewport now supports horizontal scrolling
 - improved the style of the isInfinite assert in box.dart
 - fixed the position of a comment in mixed_viewport.dart
 - added a test
 - made the logic for how many items to show be more precise
2015-08-31 15:57:45 -07:00

53 lines
1.4 KiB
Dart

import 'package:quiver/testing/async.dart';
import 'package:sky/widgets.dart';
import 'package:test/test.dart';
import 'widget_tester.dart';
void main() {
test('Scrolling changes page', () {
WidgetTester tester = new WidgetTester();
List<int> pages = [0, 1, 2, 3, 4, 5];
Size pageSize = new Size(200.0, 200.0);
int currentPage;
Widget buildPage(int page) {
return new Container(
key: new ValueKey<int>(page),
width: pageSize.width,
height: pageSize.height,
child: new Text(page.toString())
);
}
Widget builder() {
return new Container(
height: pageSize.height,
child: new PageableList<int>(
padding: new EdgeDims.symmetric(horizontal: 10.0),
items: pages,
itemBuilder: buildPage,
scrollDirection: ScrollDirection.horizontal,
itemExtent: pageSize.width,
pageChanged: (int page) {
currentPage = page;
}
)
);
}
tester.pumpFrame(builder);
expect(currentPage, isNull);
new FakeAsync().run((async) {
tester.scroll(tester.findText('1'), new Offset(-300.0, 0.0));
// One frame to start the animation, a second to complete it.
tester.pumpFrame(builder);
tester.pumpFrame(builder, 5000.0);
async.elapse(new Duration(seconds: 5));
expect(currentPage, equals(2));
});
});
}