Flutter 列表视图

https://docs.flutter.dev/cookbook/lists/long-lists

 

下滑操作,加载更多

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: ListView.builder(
        itemCount: (present <= originalItems.length) ? items.length + 1 : items.length,
        itemBuilder: (context, index) {
          return (index == items.length ) ?
          Container(
            color: Colors.greenAccent,
            child: FlatButton(
              child: Text("Load More"),
              onPressed: () {
                setState(() {
                  if((present + perPage )> originalItems.length) {
                    items.addAll(
                        originalItems.getRange(present, originalItems.length));
                  } else {
                    items.addAll(
                        originalItems.getRange(present, present + perPage));
                  }
                  present = present + perPage;
                });
              },
            ),
          )

学会了吗

 

点击加载更多的时候,就往list后面不断的加数据就行了。

分类: 默认 标签: 发布于: 2022-03-18 10:30:20, 更新于: 2022-03-18 10:34:13