DavideBelsole / great_list_view

pub.dev library for flutter
MIT License
41 stars 22 forks source link

`dispatchNewList` the whole list data passed as props or getting from API #4

Closed bahung1221 closed 3 years ago

bahung1221 commented 3 years ago

Thanks for your awesome work!

The plugin worked well and really easy to use. But the first time I was stuck when I get the new list data from API and then passed the whole list to dispatchNewList, in this case there is no animation occurred. The workaround is manually comparing the old list and the new list to find the diff, and then push/remove the different items to the old list.

Not working:

var newList = await tasksDao.fetchTasks();

taskController.dispatchNewList(newList);

Working:

var removedTask = ... // Finding the diff
var newList = taskController.currentList.where((element) => element.id != removedTask.id).toList();

taskController.dispatchNewList(newList);

I think this issue will be a big improvement when it has resolved because this is frequently behaviour in my opinion.

Thanks a lot 🍻

bahung1221 commented 3 years ago

It seems there is the same issue in #3 .

bahung1221 commented 3 years ago

I just found some interested things, the above example will work if i wrapping the dispatchNewList call into a addPostFrameCallback:

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
        taskController.dispatchNewList(newList);
      });

I found that this issue is relative to my modal context, because I call dispatchNewList immediately after a modal closed by Navigator.of(context).pop(). Now I just wait for a little time before calling dispatchNewList and then everything worked like a charm!

Its weird but I think I should close this issue now 🍻