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

senior

What are some pros and cons of Scoped Model vs BLoC and vice versa?

middle

What are Streams in Flutter/Dart?

junior

How is Flutter different from a WebView based application?

Bình luận

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

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