What are Global Keys?

Technology CommunityCategory: FlutterWhat are Global Keys?
VietMX Staff asked 3 years ago
  • 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 those elements, such as BuildContext. For StatefulWidgets, global keys also provide access to 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.
  • You cannot simultaneously include two widgets in the tree with the same global key. Attempting to do so will assert at runtime.