Keys in Flutter help the framework correctly identify and preserve widgets across rebuilds — particularly important for stateful widgets in lists that get reordered, added, or removed. Understanding when keys are needed prevents subtle, confusing bugs.
What keys do
During rebuilds, Flutter MATCHES new widgets to existing elements/state by POSITION and
TYPE. Usually this works fine. But when widgets of the SAME TYPE are reordered/added/
removed in a list, position-matching gets confused → state attaches to the WRONG widget.
→ KEYS give widgets a stable IDENTITY so Flutter matches them correctly across changes.
