Flutter में keys फ्रेमवर्क को widgets को सही तरीके से identify करने और rebuilds के दौरान संरक्षित रखने में मदद करते हैं — खासकर lists में stateful widgets के लिए महत्वपूर्ण जो reorder, add या remove किए जाते हैं। यह समझना कि 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.
