Flutter – Text which changes dynamically Stateless or Stateful?

Issue

Suppose I have a text widget that changes dynamically (ie the text changes based on conditions, button clicks etc). So now is the Text stateless or Stateful?

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

Text is a Stateless widget but the content of text is changing so why is it not stateful?

Solution

Text is stateless because Text itself never does not change its content on its own, which matches the definition you mentioned.

In the case you mentioned, it will be another widget that’s going to change the content of the Text widget.

Answered By – Ali Alizadeh

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *