Keys katika Flutter husaidia framework kutambua na kuhifadhi widgets kwa usahihi katika rebuilds — muhimu hasa kwa stateful widgets katika lists zinazopangwa upya, kuongezwa, au kuondolewa. Kuelewa lini keys zinahitajika huzuia bugs za hila na zinazochanganya.
Keys hufanya nini
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.
