What are the keys used in the Flutter framework?

keys are very less used in the flutter framework , it works when the widget moves around in the widget tree. According to the documentation A Key is an identifier for Widgets, Elements and SemanticsNodes. A key that uses a value of a particular type to identify itself.

There are 4 types of keys that exist in Flutter

  1. Value Key
  2. Object Key
  3. Unique Key
  4. GlobalKeys

ValueKey:-

It is a regular key that uses simple Integer and string value.

ObjectKey:-

If you want to show more complex data rather than string or integer then you can use the Object key.

Unique key:-

This will provide your widget unique key every time. never put this key in the build method.

GlobalKey:-

The global key is used for maintaining state across the app because these are global variables

Further Reading:

https://api.flutter.dev/flutter/foundation/Key-class.html

https://www.youtube.com/watch?v=kn0EOS-ZiIc

Leave a Comment