In the flutter documentation, it states
"A stateless widget never changes. Icon, IconButton, and Text are examples of stateless widgets. Stateless widgets subclass StatelessWidget.
A stateful widget is dynamic: for example, it can change its appearance in response to events triggered by user interactions or when it receives data. Checkbox, Radio, Slider, InkWell, Form, and TextField are examples of stateful widgets. Stateful widgets subclass StatefulWidget."
This is confusing to me, because an IconButton can change its appearance in response to events triggered by user interactions. I am not understanding the distinction between stateless and stateful given this example
when making a custom widget, I am unsure when to make it stateful or stateless
IconButtonmight be stateless but it uses widgets that are stateful (ButtonStyleButtonin this case). The state is held byButtonStyleButtonandIconButtonis only a wrapper around it to make it easier to use, set default values or use the correct theme.Always go for a
StatelessWidgetif you can. You only needStatefulWidgetif you need to save something in the state (and usesetState) or any other method of theStatefulWidgetlikeinitStatefor example. You could useinitStateto trigger an http call to an API only once when the widget is mounted for example.