Keys Flutter میں فریم ورک کو دوبارہ بنائے جانے کے دوران widgets کو صحیح طریقے سے شناخت کرنے اور محفوظ رکھنے میں مدد دیتے ہیں — خاص طور پر stateful widgets in lists کے لیے اہم ہیں جو دوبارہ ترتیب دیے جاتے ہیں، شامل یا ہٹائے جاتے ہیں۔ یہ سمجھنا کہ 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.
