Multiple widgets used the same GlobalKey

Multiple widgets used the same GlobalKey.

Quick Answer

A GlobalKey was assigned to more than one widget simultaneously.

Why This Happens

In Flutter, each GlobalKey must be associated with exactly one widget at a time. This error often occurs in animated lists or when conditionally showing widgets that share a key. Ensure each widget gets its own unique key instance.

The Problem

final _formKey = GlobalKey<FormState>();
// In a PageView where both pages exist simultaneously:
PageView(
  children: [
    Form(key: _formKey, child: page1Fields()),
    Form(key: _formKey, child: page2Fields()),
  ],
)

The Fix

final _formKey1 = GlobalKey<FormState>();
final _formKey2 = GlobalKey<FormState>();
PageView(
  children: [
    Form(key: _formKey1, child: page1Fields()),
    Form(key: _formKey2, child: page2Fields()),
  ],
)

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: Multiple widgets used the same GlobalKey. Two live widgets share a key.

  2. 2

    Find the cause

    Check if a GlobalKey is reused across multiple widgets that can exist in the tree simultaneously.

  3. 3

    Apply the fix

    Create separate GlobalKey instances for each widget, or restructure to ensure only one widget uses the key at a time.

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