What is the difference between ValueKey, ObjectKey, and UniqueKey?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
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.
Common Mistake
Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Flutter project.