Les keys dans Flutter aident le framework à identifier correctement et préserver les widgets lors des reconstructions — particulièrement important pour les widgets stateful dans des listes qui sont réordonnés, ajoutés ou supprimés. Comprendre quand les keys sont nécessaires prévient les bugs subtils et déroutants.
À quoi servent les keys
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.
