Câu hỏi phỏng vấn Flutter
Câu hỏi

What are StatefulWidget a...

Câu trả lời

In Flutter, a StatefulWidget is defined using two separate classes: the StatefulWidget class itself and a corresponding State class. This design decision has several key reasons:

  1. Widgets are immutable, so the StatefulWidget must also be immutable. However, the state of the widget needs to be mutable in order to change over time. By separating the widget and state into two classes, the immutability of the widget can be preserved while allowing the state to be mutable[1][2].

  2. If the StatefulWidget and State were combined into a single class, creating a new instance of the widget (e.g. when its parent is updated) would reset the state every time. By separating them, the framework can create multiple instances of the StatefulWidget while preserving the same State instance[2].

  3. The State class has access to the StatefulWidget via the widget property. This allows the state to reference properties of the specific StatefulWidget subclass. The generic type parameter of State is used to specify the type of StatefulWidget it corresponds to[2].

...

expert

expert

Gợi ý câu hỏi phỏng vấn

entry

What is Flutter?

junior

What is Fat Arrow Notation in Dart and when do you use it?

senior

Explain async , await in Flutter/Dart?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào