flutter widget_error ai_generated true

Widget rebuild issue: duplicate GlobalKey detected in widget tree

ID: flutter/missing-key-properties

Also available as: JSON · Markdown
82%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3 active

Root Cause

Widget keys not used or used incorrectly causing rebuild problems, lost state, or duplicate GlobalKey errors in lists and animated widgets.

generic

Workarounds

  1. 92% success Use ValueKey with a stable unique identifier from the data
    ListView.builder(itemBuilder: (ctx, i) => ListTile(key: ValueKey(items[i].id), ...))

    Sources: https://api.flutter.dev/

  2. 85% success Use ObjectKey when items lack a unique ID
    ObjectKey(item)  // uses object identity; works when same object reference is reused
  3. 80% success Use GlobalKey only when you need to access widget state across the tree
    final _formKey = GlobalKey<FormState>();  // one GlobalKey per widget instance, never reuse

Dead Ends

Common approaches that don't work:

  1. Use UniqueKey() on every widget to force rebuilds 85% fail

    UniqueKey creates a new key every build, destroying and recreating the widget each time. Defeats the purpose of keys.

  2. Use index as key in a list (Key(index.toString())) 78% fail

    Index-based keys break when items are reordered, inserted, or deleted — state attaches to wrong items