Keys i Flutter hjelper rammeverket med å korrekt identifisere og bevare widgets på tvers av gjenoppbygginger — særlig viktig for stateful widgets i lister som blir omordnet, lagt til eller fjernet. Å forstå når keys er nødvendig forebygger subtile, forvirrende bugs.
Hva keys gjø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.
