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

What are keys in Flutter and when to use it?

Câu trả lời

Keys in Flutter are unique identifiers used to track and maintain the state of widgets as they move around or are modified in the widget tree[1][2][3]. They help the framework efficiently update the user interface by identifying which widgets have changed between renders.

You should use keys in the following situations[1][2][3]:

  • When modifying a collection of widgets of the same type that hold state, such as adding, removing, or reordering items in a ListView
  • To preserve the state of a widget when it moves to a different location in the widget tree
  • To maintain the scroll position of a ListView when the list contents change
  • To enable animations when adding, removing or reordering widgets

There are several types of keys to choose from[1][2][4]:

  • ValueKey - uses a simple value like a string or integer to identify the widget
  • ObjectKey - uses a unique object to identify the widget, useful for...
middle

middle

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

middle

What is ScopedModel / BLoC Pattern?

senior

How to compare two dates that are constructed differently in Dart?

senior

What's the difference between async and async* in Dart?

Bình luận

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

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