Keys Flutter ਵਿੱਚ framework ਨੂੰ rebuilds ਦੇ ਦੌਰਾਨ widgets ਨੂੰ ਸਹੀ ਢੰਗ ਨਾਲ ਪਛਾਣਨ ਅਤੇ preserve ਕਰਨ ਵਿੱਚ ਮਦਦ ਕਰਦੇ ਹਨ — ਖਾਸ ਤੌਰ 'ਤੇ lists ਵਿੱਚ stateful widgets ਲਈ ਮਹੱਤਵਪੂਰਨ ਜੋ reorder, ਜੋੜੇ ਜਾਂ ਹਟਾਏ ਜਾਂਦੇ ਹਨ। ਸਮਝਣਾ ਕਿ 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.
