If a widget has the same style all over the project. We make it common so that we can easily use that with a minimal number of lines. But which one should I use to create a common widget.
Let's assume I have a text widget and text form field widget with the same style. Which one should I use?
What if the text widget has a dynamic string? and what if the text widget has a simple String?
- Stateless widget / stateful widget or
- Simple Function with named params
According to flutter team,
Widgetsare better thanhelperMethods, refer to the video Widgets vs HelperMethods,StatelessWidgetsare lighter thanStatefulWidgetso as long as you can useStatelessWidgetover theStatefulWidgetpick theStatelessWidget, but some widget might not work if it was in aStatelessWidgetsuch as theTextFieldif you try to put a
TextFieldinside aStatelessWidgetit will clear it's value everytime you open the keyboard or a dialog pops up, soStatelessWidgetsare the best but sometimes it wont workStatefulWidgetare the second bes optionhelperMethodsare good only if you have a widget with a shared style inside a single screen