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