DavideBelsole / great_list_view

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

Crash when calling setState(() => dispatcher.dispatchNewList(...)) #18

Closed mregnauld closed 2 years ago

mregnauld commented 2 years ago

In my Flutter project, I use the great_list_view library, following the Example 5 in the ReadMe.

Sometimes, I need to update items, so I call:

setState(() => dispatcher.dispatchNewList(myNewList));

But for some reason, I get the following error:

setState() callback argument returned a Future.
The setState() method on ListeTitresCleState#30d55 was called with a closure or method that returned a Future. Maybe it is marked as "async".
Instead of performing asynchronous work inside a call to setState(), first execute the work (without updating the widget state), and then synchronously update the state inside a call to setState().

What is really surprising is that I only get that error when I run my app in Debug Mode (not in Profile / Release Mode)!

Can I get some help on that?

Thanks.

tRuNKator commented 2 years ago

Hi. Just use block body

setState(() {
  dispatcher.dispatchNewList(myNewList);
});

Error thrown by framework, and doesn't related to plugin. for details just look at the setState method code

mregnauld commented 2 years ago

Wow!!! I wasn't expecting that, but yeah, it works! Thank you so much!