[New post] What is difference between Stateful and Stateless Flutter
Sanjib Sinha posted: " Illustration by Katerina Limpitsouni Stateless widgets are immutable. Since their properties cannot change, all values are final. On the contrary, stateful widgets maintain state. That is the main difference. However, we can use state using Sta"
Stateless widgets are immutable. Since their properties cannot change, all values are final. On the contrary, stateful widgets maintain state.
That is the main difference. However, we can use state using Stateless widget also. And, in fact, it matters in flutter performance.
For that reason, widgets are rebuilt with the change of the state.
Does that affect flutter application?
Certainly, that rebuilds widgets and affects the performance.
Then what should we do to solve that problem? When should I use provider Flutter?
We should use provider package to solve that problem.
Why should we use provider package?
The main reason is, provider package will rebuild only the widget that needs the value. The widget that needs the value is known as consumer.
As a result, that consumer widget only rebuilds itself. For example, consider a simple counter. As we press the button to change the state, each pressing changes the state and rebuilds the widget.
For a stateful widget, that rebuild affects the whole tree of widgets.
In Android Studio, we can watch the flutter performance.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.