Commit 332a2303 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Rename and refactor ScrollView hierarchy (#7865)

This prepares us for a CustomScrollView that takes slivers.
parent 7fea0593
...@@ -588,7 +588,7 @@ class GalleryDrawer extends StatelessWidget { ...@@ -588,7 +588,7 @@ class GalleryDrawer extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Drawer( return new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new FancyDrawerHeader(), new FancyDrawerHeader(),
new DrawerItem( new DrawerItem(
......
...@@ -123,7 +123,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -123,7 +123,7 @@ class CardCollectionState extends State<CardCollection> {
return new Drawer( return new Drawer(
child: new IconTheme( child: new IconTheme(
data: const IconThemeData(color: Colors.black), data: const IconThemeData(color: Colors.black),
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new DrawerHeader(child: new Center(child: new Text('Options'))), new DrawerHeader(child: new Center(child: new Text('Options'))),
buildDrawerCheckbox("Make card labels editable", _editable, _toggleEditable), buildDrawerCheckbox("Make card labels editable", _editable, _toggleEditable),
......
...@@ -84,7 +84,7 @@ class PageableListAppState extends State<PageableListApp> { ...@@ -84,7 +84,7 @@ class PageableListAppState extends State<PageableListApp> {
Widget _buildDrawer() { Widget _buildDrawer() {
return new Drawer( return new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new DrawerHeader(child: new Center(child: new Text('Options'))), new DrawerHeader(child: new Center(child: new Text('Options'))),
new DrawerItem( new DrawerItem(
......
...@@ -134,7 +134,7 @@ class CardsDemo extends StatelessWidget { ...@@ -134,7 +134,7 @@ class CardsDemo extends StatelessWidget {
appBar: new AppBar( appBar: new AppBar(
title: new Text('Travel stream') title: new Text('Travel stream')
), ),
body: new ScrollView( body: new ListView(
itemExtent: TravelDestinationItem.height, itemExtent: TravelDestinationItem.height,
padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0), padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
children: destinations.map((TravelDestination destination) { children: destinations.map((TravelDestination destination) {
......
...@@ -41,7 +41,7 @@ class _ChipDemoState extends State<ChipDemo> { ...@@ -41,7 +41,7 @@ class _ChipDemoState extends State<ChipDemo> {
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Chips')), appBar: new AppBar(title: new Text('Chips')),
body: new ScrollView( body: new ListView(
children: chips.map((Widget widget) { children: chips.map((Widget widget) {
return new Container( return new Container(
height: 100.0, height: 100.0,
......
...@@ -98,7 +98,7 @@ class ColorSwatchTabView extends StatelessWidget { ...@@ -98,7 +98,7 @@ class ColorSwatchTabView extends StatelessWidget {
}).toList()); }).toList());
} }
return new ScrollView( return new ListView(
itemExtent: kColorItemHeight, itemExtent: kColorItemHeight,
children: colorItems, children: colorItems,
); );
......
...@@ -165,7 +165,7 @@ class _DataTableDemoState extends State<DataTableDemo> { ...@@ -165,7 +165,7 @@ class _DataTableDemoState extends State<DataTableDemo> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Data tables')), appBar: new AppBar(title: new Text('Data tables')),
body: new ScrollView( body: new ListView(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
children: <Widget>[ children: <Widget>[
new PaginatedDataTable( new PaginatedDataTable(
......
...@@ -89,7 +89,7 @@ class DialogDemoState extends State<DialogDemo> { ...@@ -89,7 +89,7 @@ class DialogDemoState extends State<DialogDemo> {
appBar: new AppBar( appBar: new AppBar(
title: new Text('Dialogs') title: new Text('Dialogs')
), ),
body: new ScrollView( body: new ListView(
padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 72.0), padding: const EdgeInsets.symmetric(vertical: 24.0, horizontal: 72.0),
children: <Widget>[ children: <Widget>[
new RaisedButton( new RaisedButton(
......
...@@ -88,7 +88,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -88,7 +88,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
title: new Text('Navigation drawer'), title: new Text('Navigation drawer'),
), ),
drawer: new Drawer( drawer: new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new UserAccountsDrawerHeader( new UserAccountsDrawerHeader(
accountName: new Text('Zach Widget'), accountName: new Text('Zach Widget'),
......
...@@ -157,7 +157,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> { ...@@ -157,7 +157,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
) )
] ]
), ),
body: new ScrollView( body: new ListView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
children: <Widget>[ children: <Widget>[
new Container( new Container(
......
...@@ -339,7 +339,7 @@ class GridListDemoState extends State<GridListDemo> { ...@@ -339,7 +339,7 @@ class GridListDemoState extends State<GridListDemo> {
body: new Column( body: new Column(
children: <Widget>[ children: <Widget>[
new Expanded( new Expanded(
child: new ScrollGrid.count( child: new GridView.count(
crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3, crossAxisCount: (orientation == Orientation.portrait) ? 2 : 3,
mainAxisSpacing: 4.0, mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0, crossAxisSpacing: 4.0,
......
...@@ -161,7 +161,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -161,7 +161,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
) )
] ]
), ),
body: new ScrollView( body: new ListView(
children: leaveBehindItems.map(buildItem).toList() children: leaveBehindItems.map(buildItem).toList()
) )
); );
......
...@@ -40,7 +40,7 @@ class ListDemoState extends State<ListDemo> { ...@@ -40,7 +40,7 @@ class ListDemoState extends State<ListDemo> {
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border(top: new BorderSide(color: Colors.black26)) border: new Border(top: new BorderSide(color: Colors.black26))
), ),
child: new ScrollView( child: new ListView(
shrinkWrap: true, shrinkWrap: true,
children: <Widget>[ children: <Widget>[
new ListItem( new ListItem(
......
...@@ -83,7 +83,7 @@ class MenuDemoState extends State<MenuDemo> { ...@@ -83,7 +83,7 @@ class MenuDemoState extends State<MenuDemo> {
) )
] ]
), ),
body: new ScrollView( body: new ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: const EdgeInsets.symmetric(vertical: 8.0),
children: <Widget>[ children: <Widget>[
// Pressing the PopupMenuButton on the right of this item shows // Pressing the PopupMenuButton on the right of this item shows
......
...@@ -29,7 +29,7 @@ class _SnackBarDemoState extends State<SnackBarDemo> { ...@@ -29,7 +29,7 @@ class _SnackBarDemoState extends State<SnackBarDemo> {
int _snackBarIndex = 1; int _snackBarIndex = 1;
Widget buildBody(BuildContext context) { Widget buildBody(BuildContext context) {
return new ScrollView( return new ListView(
padding: const EdgeInsets.all(24.0), padding: const EdgeInsets.all(24.0),
children: <Widget>[ children: <Widget>[
new Text(_text1), new Text(_text1),
......
...@@ -127,7 +127,7 @@ class TabsDemo extends StatelessWidget { ...@@ -127,7 +127,7 @@ class TabsDemo extends StatelessWidget {
), ),
body: new TabBarView( body: new TabBarView(
children: _allPages.keys.map((_Page page) { children: _allPages.keys.map((_Page page) {
return new ScrollView( return new ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
itemExtent: _CardDataItem.height, itemExtent: _CardDataItem.height,
children: _allPages[page].map((_CardData data) { children: _allPages[page].map((_CardData data) {
......
...@@ -22,7 +22,7 @@ class TooltipDemo extends StatelessWidget { ...@@ -22,7 +22,7 @@ class TooltipDemo extends StatelessWidget {
), ),
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new ScrollView( return new ListView(
children: <Widget>[ children: <Widget>[
new Text(_introText, style: theme.textTheme.subhead), new Text(_introText, style: theme.textTheme.subhead),
new Row( new Row(
......
...@@ -66,7 +66,7 @@ class TypographyDemo extends StatelessWidget { ...@@ -66,7 +66,7 @@ class TypographyDemo extends StatelessWidget {
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Typography')), appBar: new AppBar(title: new Text('Typography')),
body: new ScrollView(children: styleItems) body: new ListView(children: styleItems)
); );
} }
} }
...@@ -305,6 +305,6 @@ class GalleryDrawer extends StatelessWidget { ...@@ -305,6 +305,6 @@ class GalleryDrawer extends StatelessWidget {
)); ));
} }
return new Drawer(child: new ScrollView(children: allDrawerItems)); return new Drawer(child: new ListView(children: allDrawerItems));
} }
} }
...@@ -203,7 +203,7 @@ class GridLists { ...@@ -203,7 +203,7 @@ class GridLists {
// START gridlists // START gridlists
// Creates a scrollable grid list with images // Creates a scrollable grid list with images
// loaded from the web. // loaded from the web.
new ScrollGrid.count( new GridView.count(
crossAxisCount: 3, crossAxisCount: 3,
childAspectRatio: 1.0, childAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0), padding: const EdgeInsets.all(4.0),
......
...@@ -76,12 +76,12 @@ class AdaptiveContainer extends StatelessWidget { ...@@ -76,12 +76,12 @@ class AdaptiveContainer extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) { if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) {
return new ScrollView( return new ListView(
itemExtent: _kListItemExtent, itemExtent: _kListItemExtent,
children: names.map((String name) => new AdaptedListItem(name: name)).toList(), children: names.map((String name) => new AdaptedListItem(name: name)).toList(),
); );
} else { } else {
return new ScrollGrid.extent( return new GridView.extent(
maxCrossAxisExtent: _kMaxTileWidth, maxCrossAxisExtent: _kMaxTileWidth,
children: names.map((String name) => new AdaptedGridItem(name: name)).toList(), children: names.map((String name) => new AdaptedGridItem(name: name)).toList(),
); );
......
...@@ -121,7 +121,7 @@ class StockHomeState extends State<StockHome> { ...@@ -121,7 +121,7 @@ class StockHomeState extends State<StockHome> {
Widget _buildDrawer(BuildContext context) { Widget _buildDrawer(BuildContext context) {
return new Drawer( return new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new DrawerHeader(child: new Center(child: new Text('Stocks'))), new DrawerHeader(child: new Center(child: new Text('Stocks'))),
new DrawerItem( new DrawerItem(
......
...@@ -240,7 +240,7 @@ class StockSettingsState extends State<StockSettings> { ...@@ -240,7 +240,7 @@ class StockSettingsState extends State<StockSettings> {
]); ]);
return true; return true;
}); });
return new ScrollView( return new ListView(
padding: const EdgeInsets.symmetric(vertical: 20.0), padding: const EdgeInsets.symmetric(vertical: 20.0),
children: rows, children: rows,
); );
......
...@@ -8,13 +8,13 @@ import 'package:meta/meta.dart'; ...@@ -8,13 +8,13 @@ import 'package:meta/meta.dart';
/// A tile in a material design grid list. /// A tile in a material design grid list.
/// ///
/// A grid list is a [ScrollGrid] of tiles in a vertical and horizontal /// A grid list is a [GridView] of tiles in a vertical and horizontal
/// array. Each tile typically contains some visually rich content (e.g., an /// array. Each tile typically contains some visually rich content (e.g., an
/// image) together with a [GridTileBar] in either a [header] or a [footer]. /// image) together with a [GridTileBar] in either a [header] or a [footer].
/// ///
/// See also: /// See also:
/// ///
/// * [ScrollGrid], which is a scrollable grid of tiles. /// * [GridView], which is a scrollable grid of tiles.
/// * [GridTileBar], which is typically used in either the [header] or /// * [GridTileBar], which is typically used in either the [header] or
/// [footer]. /// [footer].
/// * <https://material.google.com/components/grid-lists.html> /// * <https://material.google.com/components/grid-lists.html>
......
...@@ -542,7 +542,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin { ...@@ -542,7 +542,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
); );
} }
return new ScrollView( return new ListView(
shrinkWrap: true, shrinkWrap: true,
children: children, children: children,
); );
......
...@@ -283,7 +283,7 @@ class TwoLevelList extends StatelessWidget { ...@@ -283,7 +283,7 @@ class TwoLevelList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollView( return new ListView(
padding: padding, padding: padding,
shrinkWrap: true, shrinkWrap: true,
children: KeyedSubtree.ensureUniqueKeysForList(children), children: KeyedSubtree.ensureUniqueKeysForList(children),
......
...@@ -13,17 +13,13 @@ import 'scrollable.dart'; ...@@ -13,17 +13,13 @@ import 'scrollable.dart';
import 'sliver.dart'; import 'sliver.dart';
import 'viewport.dart'; import 'viewport.dart';
/// A convenience widget that combines common scrolling-related widgets. abstract class ScrollView extends StatelessWidget {
class ScrollView extends StatelessWidget {
ScrollView({ ScrollView({
Key key, Key key,
this.scrollDirection: Axis.vertical, this.scrollDirection: Axis.vertical,
this.reverse: false, this.reverse: false,
this.padding,
this.itemExtent,
this.physics, this.physics,
this.shrinkWrap: false, this.shrinkWrap: false,
this.children: const <Widget>[],
}) : super(key: key) { }) : super(key: key) {
assert(reverse != null); assert(reverse != null);
assert(shrinkWrap != null); assert(shrinkWrap != null);
...@@ -33,18 +29,10 @@ class ScrollView extends StatelessWidget { ...@@ -33,18 +29,10 @@ class ScrollView extends StatelessWidget {
final bool reverse; final bool reverse;
final EdgeInsets padding;
final double itemExtent;
final ScrollPhysics physics; final ScrollPhysics physics;
final bool shrinkWrap; final bool shrinkWrap;
final List<Widget> children;
SliverChildListDelegate get childrenDelegate => new SliverChildListDelegate(children);
@protected @protected
AxisDirection getDirection(BuildContext context) { AxisDirection getDirection(BuildContext context) {
// TODO(abarth): Consider reading direction. // TODO(abarth): Consider reading direction.
...@@ -58,21 +46,11 @@ class ScrollView extends StatelessWidget { ...@@ -58,21 +46,11 @@ class ScrollView extends StatelessWidget {
} }
@protected @protected
Widget buildChildLayout(BuildContext context) { List<Widget> buildSlivers(BuildContext context);
if (itemExtent != null) {
return new SliverList(
delegate: childrenDelegate,
itemExtent: itemExtent,
);
}
return new SliverBlock(delegate: childrenDelegate);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget sliver = buildChildLayout(context); List<Widget> slivers = buildSlivers(context);
if (padding != null)
sliver = new SliverPadding(padding: padding, child: sliver);
AxisDirection axisDirection = getDirection(context); AxisDirection axisDirection = getDirection(context);
return new Scrollable2( return new Scrollable2(
axisDirection: axisDirection, axisDirection: axisDirection,
...@@ -82,13 +60,13 @@ class ScrollView extends StatelessWidget { ...@@ -82,13 +60,13 @@ class ScrollView extends StatelessWidget {
return new ShrinkWrappingViewport( return new ShrinkWrappingViewport(
axisDirection: axisDirection, axisDirection: axisDirection,
offset: offset, offset: offset,
slivers: <Widget>[ sliver ], slivers: slivers,
); );
} else { } else {
return new Viewport2( return new Viewport2(
axisDirection: axisDirection, axisDirection: axisDirection,
offset: offset, offset: offset,
slivers: <Widget>[ sliver ], slivers: slivers,
); );
} }
} }
...@@ -99,61 +77,226 @@ class ScrollView extends StatelessWidget { ...@@ -99,61 +77,226 @@ class ScrollView extends StatelessWidget {
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
super.debugFillDescription(description); super.debugFillDescription(description);
description.add('$scrollDirection'); description.add('$scrollDirection');
if (shrinkWrap)
description.add('shrink-wrapping');
}
}
abstract class BoxScrollView extends ScrollView {
BoxScrollView({
Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false,
this.padding,
}) : super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
);
final EdgeInsets padding;
@override
List<Widget> buildSlivers(BuildContext context) {
Widget sliver = buildChildLayout(context);
if (padding != null)
sliver = new SliverPadding(padding: padding, child: sliver);
return <Widget>[ sliver ];
}
@protected
Widget buildChildLayout(BuildContext context);
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
if (padding != null) if (padding != null)
description.add('padding: $padding'); description.add('padding: $padding');
}
}
/// A scrollable list of boxes.
// TODO(ianh): More documentation here.
///
/// See also:
///
/// * [SingleChildScrollView], when you need to make a single child scrollable.
/// * [GridView], for a scrollable grid of boxes.
/// * [PageView], for a scrollable that works page by page.
class ListView extends BoxScrollView {
ListView({
Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false,
EdgeInsets padding,
this.itemExtent,
List<Widget> children: const <Widget>[],
}) : childrenDelegate = new SliverChildListDelegate(children), super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
);
ListView.custom({
Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false,
EdgeInsets padding,
this.itemExtent,
@required this.childrenDelegate,
}) : super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
) {
assert(childrenDelegate != null);
}
final double itemExtent;
final SliverChildListDelegate childrenDelegate;
@override
Widget buildChildLayout(BuildContext context) {
if (itemExtent != null) {
return new SliverList(
delegate: childrenDelegate,
itemExtent: itemExtent,
);
}
return new SliverBlock(delegate: childrenDelegate);
}
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
if (itemExtent != null) if (itemExtent != null)
description.add('itemExtent: $itemExtent'); description.add('itemExtent: $itemExtent');
if (shrinkWrap)
description.add('shrink-wrapping');
} }
} }
class ScrollGrid extends ScrollView { /// A scrollable grid of boxes.
ScrollGrid({ // TODO(ianh): More documentation here.
///
/// See also:
///
/// * [SingleChildScrollView], when you need to make a single child scrollable.
/// * [ListView], for a scrollable list of boxes.
/// * [PageView], for a scrollable that works page by page.
class GridView extends BoxScrollView {
GridView({
Key key, Key key,
Axis scrollDirection: Axis.vertical, Axis scrollDirection: Axis.vertical,
EdgeInsets padding, bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false, bool shrinkWrap: false,
this.gridDelegate, EdgeInsets padding,
@required this.gridDelegate,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : super(key: key, scrollDirection: scrollDirection, padding: padding, shrinkWrap: shrinkWrap, children: children); }) : childrenDelegate = new SliverChildListDelegate(children), super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
) {
assert(gridDelegate != null);
}
ScrollGrid.count({ GridView.custom({
Key key, Key key,
Axis scrollDirection: Axis.vertical, Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false,
EdgeInsets padding, EdgeInsets padding,
@required this.gridDelegate,
@required this.childrenDelegate,
}) : super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
) {
assert(gridDelegate != null);
assert(childrenDelegate != null);
}
GridView.count({
Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false, bool shrinkWrap: false,
EdgeInsets padding,
@required int crossAxisCount, @required int crossAxisCount,
double mainAxisSpacing: 0.0, double mainAxisSpacing: 0.0,
double crossAxisSpacing: 0.0, double crossAxisSpacing: 0.0,
double childAspectRatio: 1.0, double childAspectRatio: 1.0,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : gridDelegate = new SliverGridDelegateWithFixedCrossAxisCount( }) : gridDelegate = new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount, crossAxisCount: crossAxisCount,
mainAxisSpacing: mainAxisSpacing, mainAxisSpacing: mainAxisSpacing,
crossAxisSpacing: crossAxisSpacing, crossAxisSpacing: crossAxisSpacing,
childAspectRatio: childAspectRatio, childAspectRatio: childAspectRatio,
), super(key: key, scrollDirection: scrollDirection, padding: padding, shrinkWrap: shrinkWrap, children: children); ),
childrenDelegate = new SliverChildListDelegate(children), super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
);
ScrollGrid.extent({ GridView.extent({
Key key, Key key,
Axis scrollDirection: Axis.vertical, Axis scrollDirection: Axis.vertical,
EdgeInsets padding, bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false, bool shrinkWrap: false,
EdgeInsets padding,
@required double maxCrossAxisExtent, @required double maxCrossAxisExtent,
double mainAxisSpacing: 0.0, double mainAxisSpacing: 0.0,
double crossAxisSpacing: 0.0, double crossAxisSpacing: 0.0,
double childAspectRatio: 1.0, double childAspectRatio: 1.0,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : gridDelegate = new SliverGridDelegateWithMaxCrossAxisExtent( }) : gridDelegate = new SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxCrossAxisExtent, maxCrossAxisExtent: maxCrossAxisExtent,
mainAxisSpacing: mainAxisSpacing, mainAxisSpacing: mainAxisSpacing,
crossAxisSpacing: crossAxisSpacing, crossAxisSpacing: crossAxisSpacing,
childAspectRatio: childAspectRatio, childAspectRatio: childAspectRatio,
), super(key: key, scrollDirection: scrollDirection, padding: padding, shrinkWrap: shrinkWrap, children: children); ),
childrenDelegate = new SliverChildListDelegate(children), super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
);
final SliverGridDelegate gridDelegate; final SliverGridDelegate gridDelegate;
final SliverChildListDelegate childrenDelegate;
@override @override
Widget buildChildLayout(BuildContext context) { Widget buildChildLayout(BuildContext context) {
return new SliverGrid( return new SliverGrid(
...@@ -163,18 +306,53 @@ class ScrollGrid extends ScrollView { ...@@ -163,18 +306,53 @@ class ScrollGrid extends ScrollView {
} }
} }
class PageView extends ScrollView { /// A scrollable list that works page by page.
// TODO(ianh): More documentation here.
///
/// See also:
///
/// * [SingleChildScrollView], when you need to make a single child scrollable.
/// * [ListView], for a scrollable list of boxes.
/// * [GridView], for a scrollable grid of boxes.
class PageView extends BoxScrollView {
PageView({ PageView({
Key key, Key key,
Axis scrollDirection: Axis.horizontal, Axis scrollDirection: Axis.horizontal,
bool reverse: false,
ScrollPhysics physics: const PageScrollPhysics(),
bool shrinkWrap: false,
EdgeInsets padding,
List<Widget> children: const <Widget>[], List<Widget> children: const <Widget>[],
}) : super( }) : childrenDelegate = new SliverChildListDelegate(children), super(
key: key, key: key,
scrollDirection: scrollDirection, scrollDirection: scrollDirection,
physics: const PageScrollPhysics(), reverse: reverse,
children: children, physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
); );
PageView.custom({
Key key,
Axis scrollDirection: Axis.horizontal,
bool reverse: false,
ScrollPhysics physics: const PageScrollPhysics(),
bool shrinkWrap: false,
EdgeInsets padding,
@required this.childrenDelegate,
}) : super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
) {
assert(childrenDelegate != null);
}
final SliverChildListDelegate childrenDelegate;
@override @override
Widget buildChildLayout(BuildContext context) { Widget buildChildLayout(BuildContext context) {
return new SliverFill(delegate: childrenDelegate); return new SliverFill(delegate: childrenDelegate);
......
...@@ -10,13 +10,31 @@ import 'basic.dart'; ...@@ -10,13 +10,31 @@ import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
import 'scrollable.dart'; import 'scrollable.dart';
// ///
// /// The viewport will shrink-wrap the child in both axes. /// A box in which a single widget can be scrolled.
// /// ///
// /// See also: /// This widget is useful when you have a single box that will normally be
// /// * [ScrollView], which handles multiple children in a scrolling list. /// entirely visible, for example a clock face in a time picker, but you need to
// /// * [ScrollGrid], which handles multiple children in a scrolling grid. /// make sure it can be scrolled if the container gets too small in one axis
// /// * [Scrollable2], which handles arbitrary scrolling effects. /// (the scroll direction).
///
/// It is also useful if you need to shrink-wrap in both axes (the main
/// scrolling direction as well as the cross axis), as one might see in a dialog
/// or pop-up menu. In that case, you might pair the [SingleChildScrollView]
/// with a [BlockBody] child.
///
/// When you have a list of children and do not require cross-axis
/// shrink-wrapping behavior, for example a scrolling list that is always the
/// width of the screen, consider [ListView], which is vastly more efficient
/// that a [SingleChildScrollView] containing a [BlockBody] or [Column] with
/// many children.
///
/// See also:
///
/// * [ListView], which handles multiple children in a scrolling list.
/// * [GridView], which handles multiple children in a scrolling grid.
/// * [PageView], for a scrollable that works page by page.
/// * [Scrollable2], which handles arbitrary scrolling effects.
class SingleChildScrollView extends StatelessWidget { class SingleChildScrollView extends StatelessWidget {
SingleChildScrollView({ SingleChildScrollView({
Key key, Key key,
......
...@@ -18,7 +18,7 @@ void main() { ...@@ -18,7 +18,7 @@ void main() {
title: new Text('Home'), title: new Text('Home'),
), ),
drawer: new Drawer( drawer: new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new AboutDrawerItem( new AboutDrawerItem(
applicationVersion: '0.1.2', applicationVersion: '0.1.2',
......
...@@ -12,7 +12,7 @@ void main() { ...@@ -12,7 +12,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new Scaffold( new Scaffold(
drawer: new Drawer( drawer: new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new DrawerHeader( new DrawerHeader(
child: new Container( child: new Container(
......
...@@ -32,7 +32,7 @@ void main() { ...@@ -32,7 +32,7 @@ void main() {
home: new Material( home: new Material(
child: new Builder( child: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new ScrollView( return new ListView(
children: ListItem.divideItems( children: ListItem.divideItems(
context: context, context: context,
items: titles.map((String title) => new ListItem(title: new Text(title))), items: titles.map((String title) => new ListItem(title: new Text(title))),
......
...@@ -50,9 +50,9 @@ void main() { ...@@ -50,9 +50,9 @@ void main() {
}); });
testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async { testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async {
await tester.pumpWidget(new ScrollView(children: <Widget>[new LinearProgressIndicator(value: 0.0)])); await tester.pumpWidget(new ListView(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
List<Layer> layers1 = tester.layers; List<Layer> layers1 = tester.layers;
await tester.pumpWidget(new ScrollView(children: <Widget>[new LinearProgressIndicator(value: 0.5)])); await tester.pumpWidget(new ListView(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
List<Layer> layers2 = tester.layers; List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2))); expect(layers1, isNot(equals(layers2)));
}); });
......
...@@ -17,7 +17,7 @@ void main() { ...@@ -17,7 +17,7 @@ void main() {
height: 200.0, height: 200.0,
width: 300.0, width: 300.0,
child: new Scrollbar2( child: new Scrollbar2(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container(height: 40.0, child: new Text('0')), new Container(height: 40.0, child: new Text('0')),
new Container(height: 40.0, child: new Text('1')), new Container(height: 40.0, child: new Text('1')),
...@@ -35,13 +35,13 @@ void main() { ...@@ -35,13 +35,13 @@ void main() {
); );
SchedulerBinding.instance.debugAssertNoTransientCallbacks('Building a list with a scrollbar triggered an animation.'); SchedulerBinding.instance.debugAssertNoTransientCallbacks('Building a list with a scrollbar triggered an animation.');
await tester.tap(find.byType(ScrollView)); await tester.tap(find.byType(ListView));
SchedulerBinding.instance.debugAssertNoTransientCallbacks('Tapping a block with a scrollbar triggered an animation.'); SchedulerBinding.instance.debugAssertNoTransientCallbacks('Tapping a block with a scrollbar triggered an animation.');
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.scroll(find.byType(ScrollView), const Offset(0.0, -10.0)); await tester.scroll(find.byType(ListView), const Offset(0.0, -10.0));
expect(SchedulerBinding.instance.transientCallbackCount, greaterThan(0)); expect(SchedulerBinding.instance.transientCallbackCount, greaterThan(0));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
......
...@@ -115,7 +115,7 @@ void main() { ...@@ -115,7 +115,7 @@ void main() {
(WidgetTester tester) async { (WidgetTester tester) async {
double value = 0.0; double value = 0.0;
await tester.pumpWidget(new Material( await tester.pumpWidget(new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Slider( new Slider(
value: value, value: value,
......
...@@ -13,7 +13,7 @@ final Key blockKey = new Key('test'); ...@@ -13,7 +13,7 @@ final Key blockKey = new Key('test');
void main() { void main() {
testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async { testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ScrollView( new ListView(
key: blockKey, key: blockKey,
children: <Widget>[ children: <Widget>[
new Container( new Container(
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
testWidgets('Can scroll an overflowing block', (WidgetTester tester) async { testWidgets('Can scroll an overflowing block', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ScrollView( new ListView(
key: blockKey, key: blockKey,
children: <Widget>[ children: <Widget>[
new Container( new Container(
......
...@@ -7,6 +7,6 @@ import 'package:flutter/widgets.dart'; ...@@ -7,6 +7,6 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
await tester.pumpWidget(new ScrollView(children: <Widget>[new Center()])); await tester.pumpWidget(new ListView(children: <Widget>[new Center()]));
}); });
} }
...@@ -50,6 +50,6 @@ void main() { ...@@ -50,6 +50,6 @@ void main() {
}); });
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
await tester.pumpWidget(new ScrollView(children: <Widget>[new Container()])); await tester.pumpWidget(new ListView(children: <Widget>[new Container()]));
}); });
} }
...@@ -10,7 +10,7 @@ void main() { ...@@ -10,7 +10,7 @@ void main() {
DateTime currentValue; DateTime currentValue;
Widget widget = new Material( Widget widget = new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new MonthPicker( new MonthPicker(
selectedDate: new DateTime.utc(2015, 6, 9, 7, 12), selectedDate: new DateTime.utc(2015, 6, 9, 7, 12),
......
...@@ -312,7 +312,7 @@ void main() { ...@@ -312,7 +312,7 @@ void main() {
Point firstLocation, secondLocation, thirdLocation; Point firstLocation, secondLocation, thirdLocation;
await tester.pumpWidget(new MaterialApp( await tester.pumpWidget(new MaterialApp(
home: new ScrollView( home: new ListView(
children: <Widget>[ children: <Widget>[
new DragTarget<int>( new DragTarget<int>(
builder: (BuildContext context, List<int> data, List<dynamic> rejects) { builder: (BuildContext context, List<int> data, List<dynamic> rejects) {
...@@ -418,7 +418,7 @@ void main() { ...@@ -418,7 +418,7 @@ void main() {
Point firstLocation, secondLocation, thirdLocation; Point firstLocation, secondLocation, thirdLocation;
await tester.pumpWidget(new MaterialApp( await tester.pumpWidget(new MaterialApp(
home: new ScrollView( home: new ListView(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
children: <Widget>[ children: <Widget>[
new DragTarget<int>( new DragTarget<int>(
......
...@@ -135,7 +135,7 @@ void main() { ...@@ -135,7 +135,7 @@ void main() {
return new Scaffold( return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: new Drawer( drawer: new Drawer(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Text('drawer'), new Text('drawer'),
new FlatButton( new FlatButton(
......
...@@ -149,7 +149,7 @@ void main() { ...@@ -149,7 +149,7 @@ void main() {
autovalidate: true, autovalidate: true,
child: new Focus( child: new Focus(
key: focusKey, key: focusKey,
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new TextField( new TextField(
key: fieldKey key: fieldKey
......
...@@ -11,7 +11,7 @@ Key thirdKey = new Key('third'); ...@@ -11,7 +11,7 @@ Key thirdKey = new Key('third');
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => new Material( '/': (BuildContext context) => new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container(height: 100.0, width: 100.0), new Container(height: 100.0, width: 100.0),
new Card(child: new Hero(tag: 'a', child: new Container(height: 100.0, width: 100.0, key: firstKey))), new Card(child: new Hero(tag: 'a', child: new Container(height: 100.0, width: 100.0, key: firstKey))),
...@@ -21,7 +21,7 @@ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ ...@@ -21,7 +21,7 @@ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
) )
), ),
'/two': (BuildContext context) => new Material( '/two': (BuildContext context) => new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container(height: 150.0, width: 150.0), new Container(height: 150.0, width: 150.0),
new Card(child: new Hero(tag: 'a', child: new Container(height: 150.0, width: 150.0, key: secondKey))), new Card(child: new Hero(tag: 'a', child: new Container(height: 150.0, width: 150.0, key: secondKey))),
...@@ -35,7 +35,7 @@ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ ...@@ -35,7 +35,7 @@ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
class ThreeRoute extends MaterialPageRoute<Null> { class ThreeRoute extends MaterialPageRoute<Null> {
ThreeRoute() : super(builder: (BuildContext context) { ThreeRoute() : super(builder: (BuildContext context) {
return new Material( return new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container(height: 200.0, width: 200.0), new Container(height: 200.0, width: 200.0),
new Card(child: new Hero(tag: 'a', child: new Container(height: 200.0, width: 200.0, key: thirdKey))), new Card(child: new Hero(tag: 'a', child: new Container(height: 200.0, width: 200.0, key: thirdKey))),
...@@ -168,7 +168,7 @@ void main() { ...@@ -168,7 +168,7 @@ void main() {
await tester.pumpWidget(new MaterialApp( await tester.pumpWidget(new MaterialApp(
home: new Material( home: new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Hero(tag: 'a', child: new Text('foo')), new Hero(tag: 'a', child: new Text('foo')),
new Builder(builder: (BuildContext context) { new Builder(builder: (BuildContext context) {
......
...@@ -6,9 +6,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -6,9 +6,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('ScrollView itemExtent control test', (WidgetTester tester) async { testWidgets('ListView itemExtent control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ScrollView( new ListView(
itemExtent: 200.0, itemExtent: 200.0,
children: new List<Widget>.generate(20, (int i) { children: new List<Widget>.generate(20, (int i) {
return new Container( return new Container(
...@@ -27,7 +27,7 @@ void main() { ...@@ -27,7 +27,7 @@ void main() {
expect(find.text('3'), findsNothing); expect(find.text('3'), findsNothing);
expect(find.text('4'), findsNothing); expect(find.text('4'), findsNothing);
await tester.scroll(find.byType(ScrollView), const Offset(0.0, -250.0)); await tester.scroll(find.byType(ListView), const Offset(0.0, -250.0));
await tester.pump(); await tester.pump();
expect(find.text('0'), findsNothing); expect(find.text('0'), findsNothing);
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
expect(find.text('5'), findsNothing); expect(find.text('5'), findsNothing);
expect(find.text('6'), findsNothing); expect(find.text('6'), findsNothing);
await tester.scroll(find.byType(ScrollView), const Offset(0.0, 200.0)); await tester.scroll(find.byType(ListView), const Offset(0.0, 200.0));
await tester.pump(); await tester.pump();
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -49,11 +49,11 @@ void main() { ...@@ -49,11 +49,11 @@ void main() {
expect(find.text('5'), findsNothing); expect(find.text('5'), findsNothing);
}); });
testWidgets('ScrollView large scroll jump', (WidgetTester tester) async { testWidgets('ListView large scroll jump', (WidgetTester tester) async {
List<int> log = <int>[]; List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ScrollView( new ListView(
itemExtent: 200.0, itemExtent: 200.0,
children: new List<Widget>.generate(20, (int i) { children: new List<Widget>.generate(20, (int i) {
return new Builder( return new Builder(
......
...@@ -195,7 +195,7 @@ void main() { ...@@ -195,7 +195,7 @@ void main() {
StateMarkerState keyState = key.currentState; StateMarkerState keyState = key.currentState;
keyState.marker = "marked"; keyState.marker = "marked";
await tester.pumpWidget(new ScrollView( await tester.pumpWidget(new ListView(
itemExtent: 100.0, itemExtent: 100.0,
children: <Widget>[ children: <Widget>[
new Container( new Container(
......
...@@ -8,17 +8,17 @@ import 'package:flutter/widgets.dart'; ...@@ -8,17 +8,17 @@ import 'package:flutter/widgets.dart';
import 'states.dart'; import 'states.dart';
void main() { void main() {
testWidgets('Empty ScrollGrid', (WidgetTester tester) async { testWidgets('Empty GridView', (WidgetTester tester) async {
await tester.pumpWidget(new ScrollGrid.count( await tester.pumpWidget(new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
children: const <Widget>[], children: const <Widget>[],
)); ));
}); });
testWidgets('ScrollGrid.count control test', (WidgetTester tester) async { testWidgets('GridView.count control test', (WidgetTester tester) async {
List<String> log = <String>[]; List<String> log = <String>[];
await tester.pumpWidget(new ScrollGrid.count( await tester.pumpWidget(new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
children: kStates.map((String state) { children: kStates.map((String state) {
return new GestureDetector( return new GestureDetector(
...@@ -83,10 +83,10 @@ void main() { ...@@ -83,10 +83,10 @@ void main() {
log.clear(); log.clear();
}); });
testWidgets('ScrollGrid.extent control test', (WidgetTester tester) async { testWidgets('GridView.extent control test', (WidgetTester tester) async {
List<String> log = <String>[]; List<String> log = <String>[];
await tester.pumpWidget(new ScrollGrid.extent( await tester.pumpWidget(new GridView.extent(
maxCrossAxisExtent: 200.0, maxCrossAxisExtent: 200.0,
children: kStates.map((String state) { children: kStates.map((String state) {
return new GestureDetector( return new GestureDetector(
...@@ -126,11 +126,11 @@ void main() { ...@@ -126,11 +126,11 @@ void main() {
log.clear(); log.clear();
}); });
testWidgets('ScrollGrid large scroll jump', (WidgetTester tester) async { testWidgets('GridView large scroll jump', (WidgetTester tester) async {
List<int> log = <int>[]; List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ScrollGrid.extent( new GridView.extent(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
maxCrossAxisExtent: 200.0, maxCrossAxisExtent: 200.0,
childAspectRatio: 0.75, childAspectRatio: 0.75,
...@@ -186,11 +186,11 @@ void main() { ...@@ -186,11 +186,11 @@ void main() {
log.clear(); log.clear();
}); });
testWidgets('ScrollGrid - change crossAxisCount', (WidgetTester tester) async { testWidgets('GridView - change crossAxisCount', (WidgetTester tester) async {
List<int> log = <int>[]; List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ScrollGrid( new GridView(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, crossAxisCount: 4,
), ),
...@@ -217,7 +217,7 @@ void main() { ...@@ -217,7 +217,7 @@ void main() {
log.clear(); log.clear();
await tester.pumpWidget( await tester.pumpWidget(
new ScrollGrid( new GridView(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisCount: 2,
), ),
...@@ -245,11 +245,11 @@ void main() { ...@@ -245,11 +245,11 @@ void main() {
expect(find.text('4'), findsNothing); expect(find.text('4'), findsNothing);
}); });
testWidgets('ScrollGrid - change maxChildCrossAxisExtent', (WidgetTester tester) async { testWidgets('GridView - change maxChildCrossAxisExtent', (WidgetTester tester) async {
List<int> log = <int>[]; List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ScrollGrid( new GridView(
gridDelegate: new SliverGridDelegateWithMaxCrossAxisExtent( gridDelegate: new SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200.0, maxCrossAxisExtent: 200.0,
), ),
...@@ -276,7 +276,7 @@ void main() { ...@@ -276,7 +276,7 @@ void main() {
log.clear(); log.clear();
await tester.pumpWidget( await tester.pumpWidget(
new ScrollGrid( new GridView(
gridDelegate: new SliverGridDelegateWithMaxCrossAxisExtent( gridDelegate: new SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 400.0, maxCrossAxisExtent: 400.0,
), ),
......
...@@ -8,10 +8,10 @@ import 'package:flutter/widgets.dart'; ...@@ -8,10 +8,10 @@ import 'package:flutter/widgets.dart';
import 'states.dart'; import 'states.dart';
void main() { void main() {
testWidgets('ScrollView control test', (WidgetTester tester) async { testWidgets('ListView control test', (WidgetTester tester) async {
List<String> log = <String>[]; List<String> log = <String>[];
await tester.pumpWidget(new ScrollView( await tester.pumpWidget(new ListView(
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
return new GestureDetector( return new GestureDetector(
onTap: () { onTap: () {
...@@ -45,9 +45,9 @@ void main() { ...@@ -45,9 +45,9 @@ void main() {
log.clear(); log.clear();
}); });
testWidgets('ScrollView restart ballistic activity out of range', (WidgetTester tester) async { testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async {
Widget buildScrollView(int n) { Widget buildListView(int n) {
return new ScrollView( return new ListView(
children: kStates.take(n).map<Widget>((String state) { children: kStates.take(n).map<Widget>((String state) {
return new Container( return new Container(
height: 200.0, height: 200.0,
...@@ -60,9 +60,9 @@ void main() { ...@@ -60,9 +60,9 @@ void main() {
); );
} }
await tester.pumpWidget(buildScrollView(30)); await tester.pumpWidget(buildListView(30));
await tester.fling(find.byType(ScrollView), const Offset(0.0, -4000.0), 4000.0); await tester.fling(find.byType(ListView), const Offset(0.0, -4000.0), 4000.0);
await tester.pumpWidget(buildScrollView(15)); await tester.pumpWidget(buildListView(15));
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
......
...@@ -13,11 +13,11 @@ void main() { ...@@ -13,11 +13,11 @@ void main() {
for (int i = 0; i < 250; i++) for (int i = 0; i < 250; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
await tester.pumpWidget(new FlipWidget( await tester.pumpWidget(new FlipWidget(
left: new ScrollView(children: textWidgets), left: new ListView(children: textWidgets),
right: new Container() right: new Container()
)); ));
await tester.fling(find.byType(ScrollView), const Offset(0.0, -200.0), 1000.0); await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 1000.0);
await tester.pump(); await tester.pump();
tester.state<FlipWidgetState>(find.byType(FlipWidget)).flip(); tester.state<FlipWidgetState>(find.byType(FlipWidget)).flip();
......
...@@ -7,23 +7,23 @@ import 'package:flutter/widgets.dart'; ...@@ -7,23 +7,23 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
void main() { void main() {
testWidgets('ScrollGrid default control', (WidgetTester tester) async { testWidgets('GridView default control', (WidgetTester tester) async {
await tester.pumpWidget(new Center( await tester.pumpWidget(new Center(
child: new ScrollGrid.count( child: new GridView.count(
crossAxisCount: 1, crossAxisCount: 1,
), ),
)); ));
}); });
// Tests https://github.com/flutter/flutter/issues/5522 // Tests https://github.com/flutter/flutter/issues/5522
testWidgets('ScrollGrid displays correct children with nonzero padding', (WidgetTester tester) async { testWidgets('GridView displays correct children with nonzero padding', (WidgetTester tester) async {
final EdgeInsets padding = const EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0); final EdgeInsets padding = const EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0);
Widget testWidget = new Align( Widget testWidget = new Align(
child: new SizedBox( child: new SizedBox(
height: 800.0, height: 800.0,
width: 300.0, // forces the grid children to be 300..300 width: 300.0, // forces the grid children to be 300..300
child: new ScrollGrid.count( child: new GridView.count(
crossAxisCount: 1, crossAxisCount: 1,
padding: padding, padding: padding,
children: new List<Widget>.generate(10, (int index) { children: new List<Widget>.generate(10, (int index) {
......
...@@ -126,7 +126,7 @@ void main() { ...@@ -126,7 +126,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new SemanticsDebugger(
child: new Material( child: new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new RaisedButton( new RaisedButton(
onPressed: () { onPressed: () {
...@@ -160,7 +160,7 @@ void main() { ...@@ -160,7 +160,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new SemanticsDebugger(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container( new Container(
key: childKey, key: childKey,
...@@ -175,22 +175,22 @@ void main() { ...@@ -175,22 +175,22 @@ void main() {
expect(tester.getTopLeft(find.byKey(childKey)).y, equals(0.0)); expect(tester.getTopLeft(find.byKey(childKey)).y, equals(0.0));
await tester.fling(find.byType(ScrollView), const Offset(0.0, -200.0), 200.0); await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 200.0);
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0)); expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0));
await tester.fling(find.byType(ScrollView), const Offset(200.0, 0.0), 200.0); await tester.fling(find.byType(ListView), const Offset(200.0, 0.0), 200.0);
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0)); expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0));
await tester.fling(find.byType(ScrollView), const Offset(-200.0, 0.0), 200.0); await tester.fling(find.byType(ListView), const Offset(-200.0, 0.0), 200.0);
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0)); expect(tester.getTopLeft(find.byKey(childKey)).y, equals(-480.0));
await tester.fling(find.byType(ScrollView), const Offset(0.0, 200.0), 200.0); await tester.fling(find.byType(ListView), const Offset(0.0, 200.0), 200.0);
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.byKey(childKey)).y, equals(0.0)); expect(tester.getTopLeft(find.byKey(childKey)).y, equals(0.0));
...@@ -247,7 +247,7 @@ void main() { ...@@ -247,7 +247,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new SemanticsDebugger(
child: new Material( child: new Material(
child: new ScrollView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Checkbox( new Checkbox(
key: keyTop, key: keyTop,
......
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