Commit ed8c1cb6 authored by Hans Muller's avatar Hans Muller

Enable dynamic changes to itemsWrap in PageableList

parent fc6f91c2
......@@ -23,6 +23,7 @@ class PageableListApp extends App {
List<CardModel> cardModels;
Size pageSize = new Size(200.0, 200.0);
ScrollDirection scrollDirection = ScrollDirection.horizontal;
bool itemsWrap = false;
void initState() {
List<Size> cardSizes = [
......@@ -67,13 +68,18 @@ class PageableListApp extends App {
);
}
EventDisposition switchScrollDirection() {
void switchScrollDirection() {
setState(() {
scrollDirection = (scrollDirection == ScrollDirection.vertical)
? ScrollDirection.horizontal
: ScrollDirection.vertical;
});
return EventDisposition.processed;
}
void toggleItemsWrap() {
setState(() {
itemsWrap = !itemsWrap;
});
}
bool _drawerShowing = false;
......@@ -113,6 +119,13 @@ class PageableListApp extends App {
selected: scrollDirection == ScrollDirection.vertical,
child: new Text('Vertical Layout'),
onPressed: switchScrollDirection
),
new DrawerItem(
onPressed: toggleItemsWrap,
child: new Row([
new Flexible(child: new Text('Scrolling wraps around')),
new Checkbox(value: itemsWrap)
])
)
]
);
......@@ -132,7 +145,7 @@ class PageableListApp extends App {
Widget buildBody() {
Widget list = new PageableList<CardModel>(
items: cardModels,
itemsWrap: true,
itemsWrap: itemsWrap,
itemBuilder: buildCard,
scrollDirection: scrollDirection,
itemExtent: (scrollDirection == ScrollDirection.vertical)
......
......@@ -83,6 +83,10 @@ class HomogeneousViewport extends RenderObjectWrapper {
_layoutDirty = true;
itemCount = newNode.itemCount;
}
if (itemsWrap != newNode.itemsWrap) {
_layoutDirty = true;
itemsWrap = newNode.itemsWrap;
}
if (itemExtent != newNode.itemExtent) {
_layoutDirty = true;
itemExtent = newNode.itemExtent;
......
......@@ -371,7 +371,13 @@ abstract class ScrollableWidgetList extends Scrollable {
itemExtent != source.itemExtent ||
scrollDirection != source.scrollDirection;
if (itemsWrap != source.itemsWrap) {
_scrollBehavior = null;
scrollBehaviorUpdateNeeded = true;
}
padding = source.padding;
itemsWrap = source.itemsWrap;
itemExtent = source.itemExtent;
super.syncConstructorArguments(source); // update scrollDirection
......@@ -492,7 +498,6 @@ class ScrollableList<T> extends ScrollableWidgetList {
void syncConstructorArguments(ScrollableList<T> source) {
items = source.items;
itemBuilder = source.itemBuilder;
itemsWrap = source.itemsWrap;
super.syncConstructorArguments(source);
}
......
......@@ -7,6 +7,7 @@ import 'widget_tester.dart';
const Size pageSize = const Size(800.0, 600.0);
const List<int> pages = const <int>[0, 1, 2, 3, 4, 5];
int currentPage = null;
bool itemsWrap = false;
Widget buildPage(int page) {
return new Container(
......@@ -17,7 +18,7 @@ Widget buildPage(int page) {
);
}
Widget buildFrame({ bool itemsWrap: false }) {
Widget buildFrame() {
// The test framework forces the frame (and so the PageableList)
// to be 800x600. The pageSize constant reflects as much.
return new PageableList<int>(
......@@ -55,6 +56,7 @@ void main() {
test('Scroll left from page 0 to page 1', () {
WidgetTester tester = new WidgetTester();
currentPage = null;
itemsWrap = false;
tester.pumpFrame(buildFrame);
expect(currentPage, isNull);
pageLeft(tester);
......@@ -64,6 +66,7 @@ void main() {
test('Underscroll (scroll right), return to page 0', () {
WidgetTester tester = new WidgetTester();
currentPage = null;
itemsWrap = false;
tester.pumpFrame(buildFrame);
expect(currentPage, isNull);
pageRight(tester);
......@@ -72,10 +75,13 @@ void main() {
// PageableList with itemsWrap: true
itemsWrap = true;
test('Scroll left page 0 to page 1, itemsWrap: true', () {
WidgetTester tester = new WidgetTester();
currentPage = null;
tester.pumpFrame(() { return buildFrame(itemsWrap: true); });
itemsWrap = true;
tester.pumpFrame(buildFrame);
expect(currentPage, isNull);
pageLeft(tester);
expect(currentPage, equals(1));
......@@ -84,7 +90,8 @@ void main() {
test('Scroll right from page 0 to page 5, itemsWrap: true', () {
WidgetTester tester = new WidgetTester();
currentPage = null;
tester.pumpFrame(() { return buildFrame(itemsWrap: true); });
itemsWrap = true;
tester.pumpFrame(buildFrame);
expect(currentPage, isNull);
pageRight(tester);
expect(currentPage, equals(5));
......
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