What is the relation between stateful and stateless widgets in Flutter?

前端 未结 14 1897
悲&欢浪女
悲&欢浪女 2020-12-02 07:06

A stateful widget is defined as any widget which changes its state within its lifetime. But it is a very common practice for a StatelessWidget to have a S

14条回答
  •  执念已碎
    2020-12-02 07:49

    When writing an app, you’ll commonly author new widgets that are subclasses of either StatelessWidget or StatefulWidget

    Here is some Differences Between StatelessWidget and StatefulWidget Widgets:

    Stateless Widget:

    1. A widget that has an immutable state.
    2. Stateless Widgets are static widgets.
    3. They do not depend on any data change or any behavior change.
    4. Stateless Widgets do not have a state, they will be rendered once and will not update themselves, but will only be updated when external data changes.
    5. For Example: Text, Icon, RaisedButton are Stateless Widgets.

    Stateless Widget:

    1. A widget that has a mutable state.
    2. Stateful Widgets are dynamic widgets.
    3. They can be updated during runtime based on user action or data change.
    4. Stateful Widgets have an internal state and can re-render if the input data changes or if the Widget’s state changes.
    5. For Example: Checkbox, Radio Button, Slider are Stateful Widgets

提交回复
热议问题