【问题标题】:How to add pagination to FirebaseAnimatedList如何向 FirebaseAnimatedList 添加分页
【发布时间】:2018-08-28 20:15:41
【问题描述】:

我想用FirebaseAnimatedList 进行分页,但我不知道该怎么做。 我将ScrollController 设置为控制器属性,并且能够在滚动到顶部时收到通知,但之后我不知道如何获取其他数据。

有人知道如何分页吗?

代码:

int limit = 15;

 @override
  void initState() {
    this.roomId = widget.roomId;
    listScrollController = new ScrollController()..addListener(_listener);
    super.initState();
  }
     _listener() {
        if (listScrollController.position.pixels ==
                listScrollController.position.maxScrollExtent) {
          // fetch additional here
        }
      } 
    new Flexible(
            child: new FirebaseAnimatedList(
              controller: listScrollController,
              query: FirebaseDatabase.instance
                  .reference()
                  .child('chat')
                  .child(roomId)
                  .limitToLast(limit),
              padding: const EdgeInsets.all(8.0),
              reverse: true,
              sort: (a, b) => b.key.compareTo(a.key),
              //comparing timestamp of messages to check which one would appear first
              itemBuilder: (BuildContext context, DataSnapshot messageSnapshot,
                  Animation<double> animation, int index) {
                return new ChatMessageListItem(
                  messageSnapshot: messageSnapshot,
                  animation: animation,
                );
              },
            ),
          ),

【问题讨论】:

    标签: firebase flutter


    【解决方案1】:

    遗憾的是,FirebaseAnimatedList 还不支持分页。您需要为此编写自己的分页登录名并使用用户 AnimatedList 来显示子项。

    【讨论】:

    • 谢谢你,我会采取不同的方法!
    猜你喜欢
    • 2014-05-10
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 2014-07-17
    • 2019-06-03
    • 2016-12-25
    • 2015-07-22
    • 1970-01-01
    相关资源
    最近更新 更多