📱 Flutter
Advanced
What is the difference between ValueKey, ObjectKey, and UniqueKey?
Answer
ValueKey uses a value's equality to identify a widget — two ValueKeys are equal if their values are equal (e.g., ValueKey(user.id) is best when you have a stable identifier). ObjectKey uses an object's reference identity — two ObjectKeys are equal only if they wrap the exact same object instance in memory. UniqueKey is never equal to any other key — it forces Flutter to treat a widget as entirely new every time, which can be used to force a widget to reset its state. Use UniqueKey sparingly as it prevents state preservation.