I am using ListView.buildler to layer Widget, into a vertical scroll. My only issue with this approach is that when the scroll reaches the end of my content. It wraps back to the top automatically. Currently I have this:
new ListView.builder(
scrollDirection: Axis.vertical,
key: new Key(randomString(20)),
reverse: false,
primary: true,
itemBuilder: (BuildContext context, int index) {
return new Column(
children: <Widget>[
new Padding(
padding: _bookPadding,
child: new Container(
width: 106.0,
height: 162.0,
child: new FadeInImage(
placeholder: new AssetImage('assets/loading.gif'),
image: this.book.cover)
),
),
const Divider(),
new Padding(
padding: _bookPadding,
child: new Text(
this.book.bookName,
style: getTextStyle())),
const Divider(),
new Padding(
padding: _bookPadding,
child: new Text(
'By ' + this.book.author,
style: getTextStyle(), ),
),
....
Is it possible to set ListView.builder to no-wrap when it reaches the end?
答案 0 :(得分:5)
这最终很容易。不确定我是如何从文档中错过它的,我需要添加的是Item count = non-null。就我而言,由于我在单个Column小部件中构建我的所有内容,在list-view构建器中,这就是我的构建器的样子:
new ListView.builder(
scrollDirection: Axis.vertical,
key: new Key(randomString(20)),
primary: true,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return new Column(
children: <Widget>[ .....
如果它是一个糟糕的模式,我确实想知道这个实现。 ListView.Builder是否仍会渲染Component Column的每个嵌套子元素,因为Column的每个子元素都可见?
从文档:“创建按需创建的可滚动,线性的小部件数组。 此构造函数适用于具有大量(或无限)子项数的列表视图,因为仅为那些实际可见的子项调用构建器。“
答案 1 :(得分:4)
您可以跳过很多代码。有时itemBuilder非常好,特别是当你有很多小部件并且可以通过索引轻松识别你的项目时,你也可以直接使用这些孩子。 ListView documentation:
中的一个示例new ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(20.0),
children: <Widget>[
const Text('I\'m dedicating every day to you'),
const Text('Domestic life was never quite my style'),
const Text('When you smile, you knock me out, I fall apart'),
const Text('And I thought I was so smart'),
],
)