skip to Main Content

I’m using Provider in my project, I have big list of custom object (comments), If I have about 1,000 comments in the list, when I update an item in the list, let’s say I like some of comments and changing the isLike bool from false to true, it rebuilds all the list, because I’m using Selector in the list, and the notifyListeners rebuilds all the 1,000 items instead this little like change.

I googled it and didn’t find any example / doc that’s talking about it, all the examples just show how to rebuild all the list widget instead of the specific widget item.

2

Answers


  1. Each of your comments should have a Stateful part called, for example, CommentActions. With it’s own internal state, that could be set initially when you build all your comments by passing the initial values. But the actions such as likes and dislikes should only update it’s own state and do not notify the entire list.

    Login or Signup to reply.
  2. you can change status of selected item locally once you get api response through (indexWhere built-in function):

            updatedProduct?.isFavourite = true; // true when like and false when dislike
            updatedProduct?.itemId = addRemoveWishlist?.data?.product?.itemId;
            products[products.indexWhere((element) =>
            element?.entityId == updatedProduct?.entityId)] =
            updatedProduct!;
            notifyListeners();
    

    Hope this help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search