flutter
widget_error
ai_generated
true
Widget rebuild issue: duplicate GlobalKey detected in widget tree
ID: flutter/missing-key-properties
82%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 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.
genericWorkarounds
-
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/
-
85% success Use ObjectKey when items lack a unique ID
ObjectKey(item) // uses object identity; works when same object reference is reused
-
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:
-
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.
-
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