Reputation: 12566
I'd like to paginate with FirebaseAnimatedList
but I don't know how to do it.
I set ScrollController
to controller property and was able to get notified when scroll to top but I don't know how to fetch additional data after that.
Does anyone know how to paginate?
Code:
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,
);
},
),
),
Upvotes: 3
Views: 470
Reputation: 445
Sadly, FirebaseAnimatedList
does not support pagination yet. You need to write your own pagination login for that and user AnimatedList
to display children.
Upvotes: 2