EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
623 stars 210 forks source link

Jank on append #219

Closed Shawn-sudo closed 1 year ago

Shawn-sudo commented 2 years ago

Every time .appendPage() is called, jank happens for some reason

Appending 10 "messages" (which are widgets) at once: https://vimeo.com/744686389 Appending 1 message at once: https://vimeo.com/744686802 Appending 3 messages at once, no animation: https://vimeo.com/744686878

You can see the screen being shaky every time pagingController seems to call the pageRequestListener

My code looks like this:

void initState() {
    pagingController.addPageRequestListener((pageKey) {
      fetchOlderMessages_fromServer(limit: 10, pageKey: pageKey);
    });
}
/// ChatMessage is a class made with my personal code
/// Just to show the abstract
  Future<void> fetchOlderMessages_fromServer(
      {required int limit, required int pageKey}) async {
    print("fetch messages (server): $limit");

    try {
      var fetchedMessages = await widget.chatID.messagesCollectionRef
          .orderBy("time", descending: true)
          .startAfter(
              [Timestamp.fromDate(_getOldestMessageTime() ?? DateTime.now())])
          .limit(limit)
          .get();

      List<ChatMessage> messages = [];
      fetchedMessages.docs.forEach((element) {
        messages
            .add(ChatMessage.fromMap(data: element.data(), docID: element.id));
      });

      pagingController.appendPage(messages, pageKey + messages.length);

      if (fetchedMessages.docs.isEmpty) {
        pagingController.appendLastPage([]);
      }
    } catch (e) {
      print("error: $e");
    }
  }
Shawn-sudo commented 1 year ago

Hi, I think it's an issue with my own code, such as the sorting method blocking the main thread, or smth like that. I'll close this issue