المفاتيح (Keys) في Flutter تساعد الإطار عمل على تحديد والحفاظ على الـ widgets بشكل صحيح عبر إعادة البناء — وهذا مهم بشكل خاص لـ الـ stateful widgets في القوائم التي يتم إعادة ترتيبها أو إضافة عناصر جديدة أو حذفها. فهم متى تكون المفاتيح ضرورية يمنع الأخطاء الدقيقة والمربكة.
ما الذي تفعله المفاتيح
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.
