2
votes

I was wondering how setState() really works in Flutter.

I have a page that contains a ListView and a Play button. When I press the button, I call setState() to change the Icon from the button. This triggers the ListView to rebuild the whole list which it's items.

Should I wrap my button in a new StatefulWidget, so rebuilding the button won't rebuild the whole page? Or is Flutter smart enough to figure out what has really changed and only rebuild these widgets? If the letter is the case, how does it work? I'm sure the build method of my List items is being called...

1

1 Answers

0
votes

You should know more about Reactive programming and Streams in Flutter. Reactive programming is architecture around the notion of Streams and listeners. Streams allow you to rebuild only one specific element, it's much more efficient!

Video from Google I/O '18 about it:

https://www.youtube.com/watch?v=RS36gBEp8OI

Great post that explain the notions of Streams and Reactive Programming:

https://www.didierboelens.com/2018/08/reactive-programming---streams---bloc/

It's intermediate difficulty method, but it's worth to learn it!

Good Luck!