【问题标题】:How to achieve the effect that pull down to load more data in flutter project,but not pull down to refresh data?如何在flutter项目中实现下拉加载更多数据,而不是下拉刷新数据的效果?
【发布时间】:2019-06-20 07:09:37
【问题描述】:

我正在写一个聊天应用程序,但是我在实现下拉加载更多数据的效果时遇到了问题。

我要达到的效果:

  1. 用户发送的聊天数据将在 ListView 表单中从上到下显示。
  2. 当用户下拉 ListView 时,会加载旧的聊天数据,但不会立即显示。当用户滚动 ListView 时,应该显示旧的字符数据。

片段:

class _List3PageState extends State<List3Page> {
  List<String> _stringList = [];
  int i = 0;

  @override
  void initState() {
    super.initState();

    for (int i = 0; i < 5; i++) {
      _stringList.add('chat data');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('pull down to load more data'),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: ListView.builder(
              itemCount: _stringList.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  child: Text(_stringList[index]),
                );
              },
            ),
          ),
          FlatButton(
              onPressed: () {
                List<String> oldData = [];
                oldData.add('chat old data $i');
                i += 1;
                oldData.add('chat old data $i');
                i += 1;
                oldData.add('chat old data $i');
                i += 1;
                oldData.add('chat old data $i');
                i += 1;
                _stringList.insertAll(0, oldData);
                setState(() {});
              },
              child: Text('load old chat data')),
        ],
      ),
    );
  }
}

【问题讨论】:

    标签: flutter


    【解决方案1】:

    也许您可以用手势检测器包围您的列表视图,然后使用 onVerticalDragDown 事件。

    【讨论】:

      猜你喜欢
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 2019-09-26
      • 2019-12-23
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多