Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jank on append #219

Closed
Shawn-sudo opened this issue Aug 30, 2022 · 1 comment
Closed

Jank on append #219

Shawn-sudo opened this issue Aug 30, 2022 · 1 comment

Comments

@Shawn-sudo
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant