Commit 627c1ffb authored by Adam Barth's avatar Adam Barth

Replace ScrollableList with ScrollableList2

ScrollableList2 is complete and subsumes all the use cases for the original
ScrollableList.
parent fa15fc2d
...@@ -14,7 +14,7 @@ class FitnessItemList extends StatelessComponent { ...@@ -14,7 +14,7 @@ class FitnessItemList extends StatelessComponent {
final FitnessItemHandler onDismissed; final FitnessItemHandler onDismissed;
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableList2( return new ScrollableList(
padding: const EdgeDims.all(4.0), padding: const EdgeDims.all(4.0),
itemExtent: kFitnessItemHeight, itemExtent: kFitnessItemHeight,
children: items.map((FitnessItem item) => item.toRow(onDismissed: onDismissed)) children: items.map((FitnessItem item) => item.toRow(onDismissed: onDismissed))
......
...@@ -14,7 +14,7 @@ class StockList extends StatelessComponent { ...@@ -14,7 +14,7 @@ class StockList extends StatelessComponent {
final StockRowActionCallback onAction; final StockRowActionCallback onAction;
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableList2( return new ScrollableList(
itemExtent: StockRow.kHeight, itemExtent: StockRow.kHeight,
children: stocks.map((Stock stock) { children: stocks.map((Stock stock) {
return new StockRow( return new StockRow(
......
...@@ -393,7 +393,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -393,7 +393,7 @@ class CardCollectionState extends State<CardCollection> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget cardCollection; Widget cardCollection;
if (_fixedSizeCards) { if (_fixedSizeCards) {
cardCollection = new ScrollableList2 ( cardCollection = new ScrollableList (
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null, snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
snapAlignmentOffset: _cardCollectionSize.height / 2.0, snapAlignmentOffset: _cardCollectionSize.height / 2.0,
itemExtent: _cardModels[0].height, itemExtent: _cardModels[0].height,
......
...@@ -72,7 +72,7 @@ class MediaQueryExample extends StatelessComponent { ...@@ -72,7 +72,7 @@ class MediaQueryExample extends StatelessComponent {
items.add(new AdaptiveItem("Item $i")); items.add(new AdaptiveItem("Item $i"));
if (MediaQuery.of(context).size.width < _gridViewBreakpoint) { if (MediaQuery.of(context).size.width < _gridViewBreakpoint) {
return new ScrollableList2( return new ScrollableList(
itemExtent: 50.0, itemExtent: 50.0,
children: items.map((AdaptiveItem item) => item.toListItem()) children: items.map((AdaptiveItem item) => item.toListItem())
); );
......
...@@ -30,7 +30,7 @@ class ScrollbarAppState extends State<ScrollbarApp> { ...@@ -30,7 +30,7 @@ class ScrollbarAppState extends State<ScrollbarApp> {
final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter(); final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Widget _buildMenu(BuildContext context) { Widget _buildMenu(BuildContext context) {
return new ScrollableList2( return new ScrollableList(
itemExtent: _itemExtent, itemExtent: _itemExtent,
scrollableListPainter: _scrollbarPainter, scrollableListPainter: _scrollbarPainter,
children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i)) children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i))
......
...@@ -42,7 +42,7 @@ class _MaterialListState extends State<MaterialList> { ...@@ -42,7 +42,7 @@ class _MaterialListState extends State<MaterialList> {
ScrollbarPainter _scrollbarPainter = new ScrollbarPainter(); ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableList2( return new ScrollableList(
initialScrollOffset: config.initialScrollOffset, initialScrollOffset: config.initialScrollOffset,
scrollDirection: ScrollDirection.vertical, scrollDirection: ScrollDirection.vertical,
onScroll: config.onScroll, onScroll: config.onScroll,
......
...@@ -666,59 +666,6 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends ...@@ -666,59 +666,6 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
typedef Widget ItemBuilder<T>(BuildContext context, T item, int index); typedef Widget ItemBuilder<T>(BuildContext context, T item, int index);
/// A wrapper around [ScrollableWidgetList] that helps you translate a list of
/// model objects into a scrollable list of widgets. Assumes all the widgets
/// have the same height.
class ScrollableList<T> extends ScrollableWidgetList {
ScrollableList({
Key key,
double initialScrollOffset,
ScrollDirection scrollDirection: ScrollDirection.vertical,
ScrollListener onScroll,
SnapOffsetCallback snapOffsetCallback,
double snapAlignmentOffset: 0.0,
this.items,
this.itemBuilder,
bool itemsWrap: false,
double itemExtent,
EdgeDims padding,
ScrollableListPainter scrollableListPainter
}) : super(
key: key,
initialScrollOffset: initialScrollOffset,
scrollDirection: scrollDirection,
onScroll: onScroll,
snapOffsetCallback: snapOffsetCallback,
snapAlignmentOffset: snapAlignmentOffset,
itemsWrap: itemsWrap,
itemExtent: itemExtent,
padding: padding,
scrollableListPainter: scrollableListPainter
);
final List<T> items;
final ItemBuilder<T> itemBuilder;
ScrollableListState<T, ScrollableList<T>> createState() => new ScrollableListState<T, ScrollableList<T>>();
}
class ScrollableListState<T, Config extends ScrollableList<T>> extends ScrollableWidgetListState<Config> {
ScrollBehavior createScrollBehavior() {
return config.itemsWrap ? new UnboundedBehavior() : super.createScrollBehavior();
}
int get itemCount => config.items.length;
List<Widget> buildItems(BuildContext context, int start, int count) {
List<Widget> result = new List<Widget>();
int begin = config.itemsWrap ? start : math.max(0, start);
int end = config.itemsWrap ? begin + count : math.min(begin + count, config.items.length);
for (int i = begin; i < end; ++i)
result.add(config.itemBuilder(context, config.items[i % itemCount], i));
return result;
}
}
/// A general scrollable list for a large number of children that might not all /// A general scrollable list for a large number of children that might not all
/// have the same height. Prefer [ScrollableWidgetList] when all the children /// have the same height. Prefer [ScrollableWidgetList] when all the children
/// have the same height because it can use that property to be more efficient. /// have the same height because it can use that property to be more efficient.
......
...@@ -11,8 +11,8 @@ import 'virtual_viewport.dart'; ...@@ -11,8 +11,8 @@ import 'virtual_viewport.dart';
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
class ScrollableList2 extends Scrollable { class ScrollableList extends Scrollable {
ScrollableList2({ ScrollableList({
Key key, Key key,
double initialScrollOffset, double initialScrollOffset,
ScrollDirection scrollDirection: ScrollDirection.vertical, ScrollDirection scrollDirection: ScrollDirection.vertical,
...@@ -44,7 +44,7 @@ class ScrollableList2 extends Scrollable { ...@@ -44,7 +44,7 @@ class ScrollableList2 extends Scrollable {
ScrollableState createState() => new _ScrollableList2State(); ScrollableState createState() => new _ScrollableList2State();
} }
class _ScrollableList2State extends ScrollableState<ScrollableList2> { class _ScrollableList2State extends ScrollableState<ScrollableList> {
ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior; ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
......
...@@ -38,7 +38,7 @@ Widget buildDismissableItem(int item) { ...@@ -38,7 +38,7 @@ Widget buildDismissableItem(int item) {
Widget widgetBuilder() { Widget widgetBuilder() {
return new Container( return new Container(
padding: const EdgeDims.all(10.0), padding: const EdgeDims.all(10.0),
child: new ScrollableList2( child: new ScrollableList(
scrollDirection: scrollDirection, scrollDirection: scrollDirection,
itemExtent: itemExtent, itemExtent: itemExtent,
children: <int>[0, 1, 2, 3, 4].where( children: <int>[0, 1, 2, 3, 4].where(
......
...@@ -99,7 +99,7 @@ void main() { ...@@ -99,7 +99,7 @@ void main() {
(key.currentState as StateMarkerState).marker = "marked"; (key.currentState as StateMarkerState).marker = "marked";
tester.pumpWidget(new ScrollableList2( tester.pumpWidget(new ScrollableList(
itemExtent: 100.0, itemExtent: 100.0,
children: <Widget>[ children: <Widget>[
new Container( new Container(
......
...@@ -17,7 +17,7 @@ void main() { ...@@ -17,7 +17,7 @@ void main() {
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new Container( child: new Container(
height: 50.0, height: 50.0,
child: new ScrollableList2( child: new ScrollableList(
key: new GlobalKey(), key: new GlobalKey(),
itemExtent: 290.0, itemExtent: 290.0,
scrollDirection: ScrollDirection.horizontal, scrollDirection: ScrollDirection.horizontal,
...@@ -57,7 +57,7 @@ void main() { ...@@ -57,7 +57,7 @@ void main() {
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new Container( child: new Container(
width: 50.0, width: 50.0,
child: new ScrollableList2( child: new ScrollableList(
key: new GlobalKey(), key: new GlobalKey(),
itemExtent: 290.0, itemExtent: 290.0,
scrollDirection: ScrollDirection.vertical, scrollDirection: ScrollDirection.vertical,
......
...@@ -13,7 +13,7 @@ Widget buildFrame() { ...@@ -13,7 +13,7 @@ Widget buildFrame() {
return new Center( return new Center(
child: new Container( child: new Container(
height: 50.0, height: 50.0,
child: new ScrollableList2( child: new ScrollableList(
itemExtent: 290.0, itemExtent: 290.0,
scrollDirection: ScrollDirection.horizontal, scrollDirection: ScrollDirection.horizontal,
children: items.map((int item) { children: items.map((int item) {
......
...@@ -9,7 +9,7 @@ import 'package:test/test.dart'; ...@@ -9,7 +9,7 @@ import 'package:test/test.dart';
const List<int> items = const <int>[0, 1, 2, 3, 4, 5]; const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
Widget buildFrame() { Widget buildFrame() {
return new ScrollableList2( return new ScrollableList(
itemExtent: 290.0, itemExtent: 290.0,
scrollDirection: ScrollDirection.vertical, scrollDirection: ScrollDirection.vertical,
children: items.map((int item) { children: items.map((int item) {
......
...@@ -29,7 +29,7 @@ Widget buildFrame() { ...@@ -29,7 +29,7 @@ Widget buildFrame() {
return new Center( return new Center(
child: new Container( child: new Container(
height: itemExtent * 2.0, height: itemExtent * 2.0,
child: new ScrollableList2( child: new ScrollableList(
key: scrollableListKey, key: scrollableListKey,
snapOffsetCallback: snapOffsetCallback, snapOffsetCallback: snapOffsetCallback,
scrollDirection: scrollDirection, scrollDirection: scrollDirection,
......
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