Home > Software engineering >  Why is IconButton considered a Stateless widget in Flutter?
Why is IconButton considered a Stateless widget in Flutter?

Time:10-12

https://docs.flutter.dev/development/ui/interactive

A stateless widget never changes. Icon, IconButton, and Text are examples of stateless widgets. Stateless widgets subclass StatelessWidget.

https://api.flutter.dev/flutter/material/IconButton-class.html

An icon button is a picture printed on a Material widget that reacts to touches by filling with color (ink).
Icon buttons are commonly used in the AppBar.actions field, but they can be used in many other places as well.
If the onPressed callback is null, then the button will be disabled and will not react to touch.

When this button reacts to user touches, that means it is interactive? Then why does it fall under Stateless category?

CodePudding user response:

The icon button is reactive, it reacts to touches. But can not change its state. Stateless means the Widget can not recompose but it does can react to userevents like tapping. Look Textfield it has the ability to recompose it self whenever the text changed, So it means it is changing its UI state which is called a 'Stateful Widget'.

I hope you understood Cheers!

  • Related