How setState() function redraw the new state after quick changes in statefull management in Flutter
It easily redraw the new state but how this concept work?
I am beginner in Flutter
How setState() function redraw the new state after quick changes in statefull management in Flutter
It easily redraw the new state but how this concept work?
I am beginner in Flutter
2
Answers
According to Flutter Documentation,
So if you want to update the state of a widget then you need to use a
setState
function. Though you must have aStateful
Widget in order to use it as a widget’s state can’t be changed in aStateless
Widget. You can read more about it on Flutter WebsiteStatefull widgets are obvious in flutter, these widgets are immutable but their states are mutable, they can change,
https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html
When you finally run your APP, you create a widget tree and for that widget tree flutter creates a corresponding element tree,
So when you call setState, the flutter framework checks for changes in widget tree and and updates corresponding element tree,
****Flutter framework is so smart that without building whole element tree from the scratch, it just updates it as per changes in widget tree.
***To get more performance benefit keep the state deeper inside the widget tree so the parents remain unaffected while flutter framework update the element tree.