Commit 31e2a500 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Use sliver-based scrolling in more places (#7892)

This patch uses sliver-based two more gallery demos, the stocks example,
in the date picker, and in markdown.
parent 0bcecef5
...@@ -128,13 +128,9 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> { ...@@ -128,13 +128,9 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Date and time pickers')), appBar: new AppBar(title: new Text('Date and time pickers')),
body: new ScrollableViewport( body: new DropdownButtonHideUnderline(
child: new Container( child: new ListView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
alignment: FractionalOffset.topLeft,
child: new DropdownButtonHideUnderline(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
new TextField( new TextField(
labelText: 'Event name', labelText: 'Event name',
...@@ -197,8 +193,6 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> { ...@@ -197,8 +193,6 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
], ],
), ),
), ),
),
),
); );
} }
} }
...@@ -101,7 +101,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing ...@@ -101,7 +101,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Progress indicators')), appBar: new AppBar(title: new Text('Progress indicators')),
body: new Center( body: new Center(
child: new ScrollableViewport( child: new SingleChildScrollView(
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: Theme.of(context).textTheme.title, style: Theme.of(context).textTheme.title,
child: new GestureDetector( child: new GestureDetector(
......
...@@ -17,17 +17,18 @@ class StockList extends StatelessWidget { ...@@ -17,17 +17,18 @@ class StockList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableList( return new ListView.builder(
key: const ValueKey<String>('stock-list'), key: const ValueKey<String>('stock-list'),
itemExtent: StockRow.kHeight, itemExtent: StockRow.kHeight,
children: stocks.map((Stock stock) { itemCount: stocks.length,
itemBuilder: (BuildContext context, int index) {
return new StockRow( return new StockRow(
stock: stock, stock: stocks[index],
onPressed: onOpen, onPressed: onOpen,
onDoubleTap: onShow, onDoubleTap: onShow,
onLongPressed: onAction onLongPressed: onAction
); );
}) },
); );
} }
} }
...@@ -544,34 +544,28 @@ class YearPicker extends StatefulWidget { ...@@ -544,34 +544,28 @@ class YearPicker extends StatefulWidget {
class _YearPickerState extends State<YearPicker> { class _YearPickerState extends State<YearPicker> {
static const double _itemExtent = 50.0; static const double _itemExtent = 50.0;
List<Widget> _buildItems(BuildContext context, int start, int count) { @override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
final ThemeData themeData = Theme.of(context); final ThemeData themeData = Theme.of(context);
final TextStyle style = themeData.textTheme.body1; final TextStyle style = themeData.textTheme.body1;
final List<Widget> items = new List<Widget>(); return new ListView.builder(
for (int i = start; i < start + count; i++) { itemExtent: _itemExtent,
final int year = config.firstDate.year + i; itemCount: config.lastDate.year - config.firstDate.year + 1,
itemBuilder: (BuildContext context, int index) {
final int year = config.firstDate.year + index;
final TextStyle itemStyle = year == config.selectedDate.year ? final TextStyle itemStyle = year == config.selectedDate.year ?
themeData.textTheme.headline.copyWith(color: themeData.accentColor) : style; themeData.textTheme.headline.copyWith(color: themeData.accentColor) : style;
items.add(new InkWell( return new InkWell(
key: new ValueKey<int>(year), key: new ValueKey<int>(year),
onTap: () { onTap: () {
config.onChanged(new DateTime(year, config.selectedDate.month, config.selectedDate.day)); config.onChanged(new DateTime(year, config.selectedDate.month, config.selectedDate.day));
}, },
child: new Center( child: new Center(
child: new Text(year.toString(), style: itemStyle) child: new Text(year.toString(), style: itemStyle),
) ),
)); );
} },
return items;
}
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context));
return new ScrollableLazyList(
itemExtent: _itemExtent,
itemCount: config.lastDate.year - config.firstDate.year + 1,
itemBuilder: _buildItems
); );
} }
} }
......
...@@ -168,6 +168,25 @@ class ListView extends BoxScrollView { ...@@ -168,6 +168,25 @@ class ListView extends BoxScrollView {
padding: padding, padding: padding,
); );
ListView.builder({
Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollPhysics physics,
bool shrinkWrap: false,
EdgeInsets padding,
this.itemExtent,
IndexedWidgetBuilder itemBuilder,
int itemCount,
}) : childrenDelegate = new SliverChildBuilderDelegate(itemBuilder, childCount: itemCount), super(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
);
ListView.custom({ ListView.custom({
Key key, Key key,
Axis scrollDirection: Axis.vertical, Axis scrollDirection: Axis.vertical,
...@@ -190,7 +209,7 @@ class ListView extends BoxScrollView { ...@@ -190,7 +209,7 @@ class ListView extends BoxScrollView {
final double itemExtent; final double itemExtent;
final SliverChildListDelegate childrenDelegate; final SliverChildDelegate childrenDelegate;
@override @override
Widget buildChildLayout(BuildContext context) { Widget buildChildLayout(BuildContext context) {
...@@ -317,7 +336,7 @@ class GridView extends BoxScrollView { ...@@ -317,7 +336,7 @@ class GridView extends BoxScrollView {
final SliverGridDelegate gridDelegate; final SliverGridDelegate gridDelegate;
final SliverChildListDelegate childrenDelegate; final SliverChildDelegate childrenDelegate;
@override @override
Widget buildChildLayout(BuildContext context) { Widget buildChildLayout(BuildContext context) {
...@@ -373,7 +392,7 @@ class PageView extends BoxScrollView { ...@@ -373,7 +392,7 @@ class PageView extends BoxScrollView {
assert(childrenDelegate != null); assert(childrenDelegate != null);
} }
final SliverChildListDelegate childrenDelegate; final SliverChildDelegate childrenDelegate;
@override @override
Widget buildChildLayout(BuildContext context) { Widget buildChildLayout(BuildContext context) {
......
...@@ -63,7 +63,7 @@ class SliverChildBuilderDelegate extends SliverChildDelegate { ...@@ -63,7 +63,7 @@ class SliverChildBuilderDelegate extends SliverChildDelegate {
int get estimatedChildCount => childCount; int get estimatedChildCount => childCount;
@override @override
bool shouldRebuild(@checked SliverChildListDelegate oldDelegate) => true; bool shouldRebuild(@checked SliverChildBuilderDelegate oldDelegate) => true;
} }
// /// // ///
......
...@@ -64,15 +64,15 @@ class MarkdownBody extends MarkdownBodyRaw { ...@@ -64,15 +64,15 @@ class MarkdownBody extends MarkdownBodyRaw {
/// by default not using syntax highlighting, but it's possible to pass in /// by default not using syntax highlighting, but it's possible to pass in
/// a custom [syntaxHighlighter]. /// a custom [syntaxHighlighter].
/// ///
/// Typically, you may want to wrap the [MarkdownBody] widget in a [Padding] and /// Typically, you may want to wrap the [MarkdownBody] widget in a
/// a [ScrollableViewport], or use the [Markdown] class /// [SingleChildScrollView], or use the [Markdown] class.
/// ///
/// new ScrollableViewport( /// ```dart
/// child: new Padding( /// new SingleChildScrollView(
/// padding: new EdgeInsets.all(16.0), /// padding: new EdgeInsets.all(16.0),
/// child: new Markdown(data: markdownSource) /// child: new Markdown(data: markdownSource),
/// ) /// ),
/// ) /// ```
MarkdownBody({ MarkdownBody({
String data, String data,
SyntaxHighlighter syntaxHighlighter, SyntaxHighlighter syntaxHighlighter,
......
...@@ -52,16 +52,16 @@ class MarkdownRaw extends StatelessWidget { ...@@ -52,16 +52,16 @@ class MarkdownRaw extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableViewport( // TODO(abarth): We should use a ListView here and lazily build the widgets
child: new Padding( // from the markdown.
return new SingleChildScrollView(
padding: padding, padding: padding,
child: createMarkdownBody( child: createMarkdownBody(
data: data, data: data,
markdownStyle: markdownStyle, markdownStyle: markdownStyle,
syntaxHighlighter: syntaxHighlighter, syntaxHighlighter: syntaxHighlighter,
onTapLink: onTapLink onTapLink: onTapLink,
) ),
)
); );
} }
...@@ -93,17 +93,17 @@ class MarkdownBodyRaw extends StatefulWidget { ...@@ -93,17 +93,17 @@ class MarkdownBodyRaw extends StatefulWidget {
/// highlighting, but it's possible to pass in a custom [syntaxHighlighter]. /// highlighting, but it's possible to pass in a custom [syntaxHighlighter].
/// ///
/// Typically, you may want to wrap the [MarkdownBodyRaw] widget in a /// Typically, you may want to wrap the [MarkdownBodyRaw] widget in a
/// [Padding] and a [ScrollableViewport], or use the [Markdown class] /// a [ScrollableViewport], or use the [Markdown class].
/// ///
/// new ScrollableViewport( /// ```dart
/// child: new Padding( /// new SingleChildScrollView(
/// padding: new EdgeInsets.all(16.0), /// padding: new EdgeInsets.all(16.0),
/// child: new MarkdownBodyRaw( /// child: new MarkdownBodyRaw(
/// data: markdownSource, /// data: markdownSource,
/// markdownStyle: myStyle /// markdownStyle: myStyle,
/// ) /// ),
/// ) /// ),
/// ) /// ```
MarkdownBodyRaw({ MarkdownBodyRaw({
this.data, this.data,
this.markdownStyle, this.markdownStyle,
......
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