Different between StatelessWidget and StatefulWidget in the flutter


As we are beginner for Flutter and many of the developers are getting confused for StatelessWidget and StatefulWidget. Here we are going to clear you what is exact difference between StatelessWidget and StatefulWidget.


Same like another language Like Swift, Kotlin Etc. you may heard about mutable and immutable property. Same things we can apply here for those widget.
In the Swift we declare let keyword with static variable and var keyword with dynamic variable.
So what is mutable and immutable ?
  • Mutable means changeable, you can change property of mutable variable or function at run time. In other world we can say it’s value is dynamic.
  • Immutable mean properly of the variable or function will not be change after set it once. In other world we can say it’s value is Static.
For StatelessWidget - It’s static, This widget will not be change after run time.


StatefulWidget - It’s dynamic, This widget will change any time where you want.
So If any API will call and JSON data are coming and You want it to display on ListView then you must use with StatefulWidget. Any operation if you want to display on run time that will be done by StatefulWidget.
StatelessWidget - Work with static data. If you render any static list that will not be change any time that you can go with this widget.



Hope you guys this is enough for your understanding. If you have any query or question then comment it.

No comments:

Post a Comment