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 {
final FitnessItemHandler onDismissed;
Widget build(BuildContext context) {
return new ScrollableList2(
return new ScrollableList(
padding: const EdgeDims.all(4.0),
itemExtent: kFitnessItemHeight,
children: items.map((FitnessItem item) => item.toRow(onDismissed: onDismissed))
......
......@@ -14,7 +14,7 @@ class StockList extends StatelessComponent {
final StockRowActionCallback onAction;
Widget build(BuildContext context) {
return new ScrollableList2(
return new ScrollableList(
itemExtent: StockRow.kHeight,
children: stocks.map((Stock stock) {
return new StockRow(
......
......@@ -393,7 +393,7 @@ class CardCollectionState extends State<CardCollection> {
Widget build(BuildContext context) {
Widget cardCollection;
if (_fixedSizeCards) {
cardCollection = new ScrollableList2 (
cardCollection = new ScrollableList (
snapOffsetCallback: _snapToCenter ? _toSnapOffset : null,
snapAlignmentOffset: _cardCollectionSize.height / 2.0,
itemExtent: _cardModels[0].height,
......
......@@ -72,7 +72,7 @@ class MediaQueryExample extends StatelessComponent {
items.add(new AdaptiveItem("Item $i"));
if (MediaQuery.of(context).size.width < _gridViewBreakpoint) {
return new ScrollableList2(
return new ScrollableList(
itemExtent: 50.0,
children: items.map((AdaptiveItem item) => item.toListItem())
);
......
......@@ -30,7 +30,7 @@ class ScrollbarAppState extends State<ScrollbarApp> {
final ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Widget _buildMenu(BuildContext context) {
return new ScrollableList2(
return new ScrollableList(
itemExtent: _itemExtent,
scrollableListPainter: _scrollbarPainter,
children: new List<Widget>.generate(_itemCount, (int i) => new _Item(i))
......
......@@ -42,7 +42,7 @@ class _MaterialListState extends State<MaterialList> {
ScrollbarPainter _scrollbarPainter = new ScrollbarPainter();
Widget build(BuildContext context) {
return new ScrollableList2(
return new ScrollableList(
initialScrollOffset: config.initialScrollOffset,
scrollDirection: ScrollDirection.vertical,
onScroll: config.onScroll,
......
......@@ -666,59 +666,6 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
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
/// have the same height. Prefer [ScrollableWidgetList] when all the children
/// have the same height because it can use that property to be more efficient.
......
......@@ -11,8 +11,8 @@ import 'virtual_viewport.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/rendering.dart';
class ScrollableList2 extends Scrollable {
ScrollableList2({
class ScrollableList extends Scrollable {
ScrollableList({
Key key,
double initialScrollOffset,
ScrollDirection scrollDirection: ScrollDirection.vertical,
......@@ -44,7 +44,7 @@ class ScrollableList2 extends Scrollable {
ScrollableState createState() => new _ScrollableList2State();
}
class _ScrollableList2State extends ScrollableState<ScrollableList2> {
class _ScrollableList2State extends ScrollableState<ScrollableList> {
ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
......
......@@ -38,7 +38,7 @@ Widget buildDismissableItem(int item) {
Widget widgetBuilder() {
return new Container(
padding: const EdgeDims.all(10.0),
child: new ScrollableList2(
child: new ScrollableList(
scrollDirection: scrollDirection,
itemExtent: itemExtent,
children: <int>[0, 1, 2, 3, 4].where(
......
......@@ -99,7 +99,7 @@ void main() {
(key.currentState as StateMarkerState).marker = "marked";
tester.pumpWidget(new ScrollableList2(
tester.pumpWidget(new ScrollableList(
itemExtent: 100.0,
children: <Widget>[
new Container(
......
......@@ -17,7 +17,7 @@ void main() {
tester.pumpWidget(new Center(
child: new Container(
height: 50.0,
child: new ScrollableList2(
child: new ScrollableList(
key: new GlobalKey(),
itemExtent: 290.0,
scrollDirection: ScrollDirection.horizontal,
......@@ -57,7 +57,7 @@ void main() {
tester.pumpWidget(new Center(
child: new Container(
width: 50.0,
child: new ScrollableList2(
child: new ScrollableList(
key: new GlobalKey(),
itemExtent: 290.0,
scrollDirection: ScrollDirection.vertical,
......
......@@ -13,7 +13,7 @@ Widget buildFrame() {
return new Center(
child: new Container(
height: 50.0,
child: new ScrollableList2(
child: new ScrollableList(
itemExtent: 290.0,
scrollDirection: ScrollDirection.horizontal,
children: items.map((int item) {
......
......@@ -9,7 +9,7 @@ import 'package:test/test.dart';
const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
Widget buildFrame() {
return new ScrollableList2(
return new ScrollableList(
itemExtent: 290.0,
scrollDirection: ScrollDirection.vertical,
children: items.map((int item) {
......
......@@ -29,7 +29,7 @@ Widget buildFrame() {
return new Center(
child: new Container(
height: itemExtent * 2.0,
child: new ScrollableList2(
child: new ScrollableList(
key: scrollableListKey,
snapOffsetCallback: snapOffsetCallback,
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