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

When would you use App state or...

Câu trả lời

Here is a concise answer to your question about when to use ephemeral state vs app state in Flutter:

Ephemeral State

Use ephemeral state when the state is:

  • Specific to a single widget or a small, localized part of the UI[1][2]
  • Not needed by other parts of the app
  • Simple enough to manage with setState()
  • Doesn't need to persist across app sessions

Examples of ephemeral state include:

  • Current page in a PageView
  • Progress of a complex animation
  • Selected tab in a BottomNavigationBar[1]

For ephemeral state, use StatefulWidget and setState() to rebuild the widget tree when the state changes[1][2].

App State

Use app state when the state:

  • Needs to be shared across multiple widgets or screens
  • Persists across app sessions
  • Is complex enough that setState() becomes unwieldy

Examples of app state include:

  • User login ...
senior

senior

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

middle

Do you know what Ephemeral state means?

middle

When do we use double.INFINITY ?

senior

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

Bình luận

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

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