Τα keys στο Flutter βοηθούν το framework να αναγνωρίζει και να διατηρεί σωστά τα widgets κατά τη διάρκεια ανακατασκευών — ιδιαίτερα σημαντικό για stateful widgets σε λίστες που αναδιατάσσονται, προστίθενται ή αφαιρούνται. Η κατανόηση του πότε χρειάζονται τα keys αποτρέπει λεπτά, συγκεχυμένα bugs.
Τι κάνουν τα 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.
