如何向FirebaseAnimatedList添加分页

时间:2018-08-28 20:15:41

标签: firebase flutter

我想与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,
                );
              },
            ),
          ),

1 个答案:

答案 0 :(得分:1)

遗憾的是,FirebaseAnimatedList还不支持分页。您需要为此和用户AnimatedList编写自己的分页登录名才能显示子级。