Duplicate GlobalKey detected in widget tree

Duplicate GlobalKey detected in widget tree.

Quick Answer

Two widgets in the tree share the same GlobalKey, which must be unique.

Why This Happens

In Flutter, a GlobalKey must be unique across the entire widget tree. If two widgets use the same GlobalKey instance, Flutter cannot correctly manage state and throws this error. This often happens when reusing a GlobalKey in a list or creating new keys in the build method.

The Problem

final key = GlobalKey<FormState>();
Column(
  children: [
    Form(key: key, child: TextField()),
    Form(key: key, child: TextField()), // Duplicate!
  ],
)

The Fix

final key1 = GlobalKey<FormState>();
final key2 = GlobalKey<FormState>();
Column(
  children: [
    Form(key: key1, child: TextField()),
    Form(key: key2, child: TextField()),
  ],
)

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: Duplicate GlobalKey detected in widget tree. This means a GlobalKey is used by more than one widget.

  2. 2

    Find the cause

    Check if a single GlobalKey instance is shared across multiple widgets, or if a list generates widgets with the same key.

  3. 3

    Apply the fix

    Create a unique GlobalKey for each widget instance, or use ValueKey or ObjectKey for list items instead.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free