Flutter ListView.builder 创建无限滚动。如何设置它在内容结束时停止?

Flutter ListView.builder creates an infinite scroll. How can I set it to stop at the end of content?

我正在使用 ListView.buildler 将 Widget 分层,形成垂直滚动。这种方法的唯一问题是当滚动到达我的内容的末尾时。它会自动回到顶部。目前我有这个:

    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(), ),
            ),
           ....

是否可以将 ListView.builder 设置为到达末尾时不换行?

这最终变得非常简单。不知道我是怎么从文档中漏掉它的,我只需要添加一个项目计数 = 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>[ .....

我确实想知道这个实现是否是一个糟糕的模式。当 Column 的每个子项都可见时,ListView.Builder 是否仍会呈现 Component Column 的每个嵌套子项?

来自文档:“创建按需创建的可滚动线性小部件阵列。 此构造函数适用于具有大量(或无限)子项的列表视图,因为仅针对实际可见的子项调用构建器。"

您可以跳过很多代码。有时 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'),
  ],
)