【发布时间】: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,
);
},
),
),
【问题讨论】: