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.
This commit is contained in:
@@ -544,34 +544,28 @@ class YearPicker extends StatefulWidget {
|
||||
class _YearPickerState extends State<YearPicker> {
|
||||
static const double _itemExtent = 50.0;
|
||||
|
||||
List<Widget> _buildItems(BuildContext context, int start, int count) {
|
||||
final ThemeData themeData = Theme.of(context);
|
||||
final TextStyle style = themeData.textTheme.body1;
|
||||
final List<Widget> items = new List<Widget>();
|
||||
for (int i = start; i < start + count; i++) {
|
||||
final int year = config.firstDate.year + i;
|
||||
final TextStyle itemStyle = year == config.selectedDate.year ?
|
||||
themeData.textTheme.headline.copyWith(color: themeData.accentColor) : style;
|
||||
items.add(new InkWell(
|
||||
key: new ValueKey<int>(year),
|
||||
onTap: () {
|
||||
config.onChanged(new DateTime(year, config.selectedDate.month, config.selectedDate.day));
|
||||
},
|
||||
child: new Center(
|
||||
child: new Text(year.toString(), style: itemStyle)
|
||||
)
|
||||
));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasMaterial(context));
|
||||
return new ScrollableLazyList(
|
||||
final ThemeData themeData = Theme.of(context);
|
||||
final TextStyle style = themeData.textTheme.body1;
|
||||
return new ListView.builder(
|
||||
itemExtent: _itemExtent,
|
||||
itemCount: config.lastDate.year - config.firstDate.year + 1,
|
||||
itemBuilder: _buildItems
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final int year = config.firstDate.year + index;
|
||||
final TextStyle itemStyle = year == config.selectedDate.year ?
|
||||
themeData.textTheme.headline.copyWith(color: themeData.accentColor) : style;
|
||||
return new InkWell(
|
||||
key: new ValueKey<int>(year),
|
||||
onTap: () {
|
||||
config.onChanged(new DateTime(year, config.selectedDate.month, config.selectedDate.day));
|
||||
},
|
||||
child: new Center(
|
||||
child: new Text(year.toString(), style: itemStyle),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,25 @@ class ListView extends BoxScrollView {
|
||||
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({
|
||||
Key key,
|
||||
Axis scrollDirection: Axis.vertical,
|
||||
@@ -190,7 +209,7 @@ class ListView extends BoxScrollView {
|
||||
|
||||
final double itemExtent;
|
||||
|
||||
final SliverChildListDelegate childrenDelegate;
|
||||
final SliverChildDelegate childrenDelegate;
|
||||
|
||||
@override
|
||||
Widget buildChildLayout(BuildContext context) {
|
||||
@@ -317,7 +336,7 @@ class GridView extends BoxScrollView {
|
||||
|
||||
final SliverGridDelegate gridDelegate;
|
||||
|
||||
final SliverChildListDelegate childrenDelegate;
|
||||
final SliverChildDelegate childrenDelegate;
|
||||
|
||||
@override
|
||||
Widget buildChildLayout(BuildContext context) {
|
||||
@@ -373,7 +392,7 @@ class PageView extends BoxScrollView {
|
||||
assert(childrenDelegate != null);
|
||||
}
|
||||
|
||||
final SliverChildListDelegate childrenDelegate;
|
||||
final SliverChildDelegate childrenDelegate;
|
||||
|
||||
@override
|
||||
Widget buildChildLayout(BuildContext context) {
|
||||
|
||||
@@ -63,7 +63,7 @@ class SliverChildBuilderDelegate extends SliverChildDelegate {
|
||||
int get estimatedChildCount => childCount;
|
||||
|
||||
@override
|
||||
bool shouldRebuild(@checked SliverChildListDelegate oldDelegate) => true;
|
||||
bool shouldRebuild(@checked SliverChildBuilderDelegate oldDelegate) => true;
|
||||
}
|
||||
|
||||
// ///
|
||||
|
||||
@@ -64,15 +64,15 @@ class MarkdownBody extends MarkdownBodyRaw {
|
||||
/// by default not using syntax highlighting, but it's possible to pass in
|
||||
/// a custom [syntaxHighlighter].
|
||||
///
|
||||
/// Typically, you may want to wrap the [MarkdownBody] widget in a [Padding] and
|
||||
/// a [ScrollableViewport], or use the [Markdown] class
|
||||
/// Typically, you may want to wrap the [MarkdownBody] widget in a
|
||||
/// [SingleChildScrollView], or use the [Markdown] class.
|
||||
///
|
||||
/// new ScrollableViewport(
|
||||
/// child: new Padding(
|
||||
/// padding: new EdgeInsets.all(16.0),
|
||||
/// child: new Markdown(data: markdownSource)
|
||||
/// )
|
||||
/// )
|
||||
/// ```dart
|
||||
/// new SingleChildScrollView(
|
||||
/// padding: new EdgeInsets.all(16.0),
|
||||
/// child: new Markdown(data: markdownSource),
|
||||
/// ),
|
||||
/// ```
|
||||
MarkdownBody({
|
||||
String data,
|
||||
SyntaxHighlighter syntaxHighlighter,
|
||||
|
||||
@@ -52,16 +52,16 @@ class MarkdownRaw extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new ScrollableViewport(
|
||||
child: new Padding(
|
||||
padding: padding,
|
||||
child: createMarkdownBody(
|
||||
data: data,
|
||||
markdownStyle: markdownStyle,
|
||||
syntaxHighlighter: syntaxHighlighter,
|
||||
onTapLink: onTapLink
|
||||
)
|
||||
)
|
||||
// TODO(abarth): We should use a ListView here and lazily build the widgets
|
||||
// from the markdown.
|
||||
return new SingleChildScrollView(
|
||||
padding: padding,
|
||||
child: createMarkdownBody(
|
||||
data: data,
|
||||
markdownStyle: markdownStyle,
|
||||
syntaxHighlighter: syntaxHighlighter,
|
||||
onTapLink: onTapLink,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,17 +93,17 @@ class MarkdownBodyRaw extends StatefulWidget {
|
||||
/// highlighting, but it's possible to pass in a custom [syntaxHighlighter].
|
||||
///
|
||||
/// 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(
|
||||
/// child: new Padding(
|
||||
/// padding: new EdgeInsets.all(16.0),
|
||||
/// child: new MarkdownBodyRaw(
|
||||
/// data: markdownSource,
|
||||
/// markdownStyle: myStyle
|
||||
/// )
|
||||
/// )
|
||||
/// )
|
||||
/// ```dart
|
||||
/// new SingleChildScrollView(
|
||||
/// padding: new EdgeInsets.all(16.0),
|
||||
/// child: new MarkdownBodyRaw(
|
||||
/// data: markdownSource,
|
||||
/// markdownStyle: myStyle,
|
||||
/// ),
|
||||
/// ),
|
||||
/// ```
|
||||
MarkdownBodyRaw({
|
||||
this.data,
|
||||
this.markdownStyle,
|
||||
|
||||
Reference in New Issue
Block a user