A key that is unique across the entire app.

Global keys uniquely identify elements. Global keys provide access to other objects that are associated with elements, such as the a BuildContext and, for StatefulWidgets, a State.

Widgets that have global keys reparent their subtrees when they are moved from one location in the tree to another location in the tree. In order to reparent its subtree, a widget must arrive at its new location in the tree in the same animation frame in which it was removed from its old location in the tree.

Global keys are relatively expensive. If you don't need any of the features listed above, consider using a Key, ValueKey, ObjectKey, or UniqueKey instead.

You cannot simultaneously include two widgets in the tree with the same global key. Attempting to do so will assert at runtime.

Inheritance
  • Object
  • Key
  • GlobalKey
Annotations
  • optionalTypeArgs

Constructors

GlobalKey({String debugLabel })

Creates a LabeledGlobalKey, which is a GlobalKey with a label used for debugging.

factory
GlobalKey.constructor()

Creates a global key without a label.

const

Properties

currentContext BuildContext

The build context in which the widget with this key builds.

read-only
currentState → T

The State for the widget in the tree that currently has this global key.

read-only
currentWidget Widget

The widget in the tree that currently has this global key.

read-only
hashCode int

The hash code for this object.

read-only, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() String

Returns a string representation of this object.

inherited