Keys i Flutter hjælper frameworket med korrekt at identificere og bevare widgets på tværs af genopbygninger — særligt vigtig for stateful widgets i lister, som bliver omordnet, tilføjet eller fjernet. Forståelse af hvornår keys er nødvendige forhindrer subtile, forvirrende bugs.
Hvad keys gør
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.
