Reputation: 17486
According to flutter doc, https://flutter.dev/docs/cookbook/forms/validation, it says the following.
When creating the form, provide a GlobalKey.
However, GlobalKey
doc says that this key is expensive and recommend developers to use other types of keys.
consider using a Key, ValueKey, ObjectKey, or UniqueKey (instead of globalKey)
What is the merit of using GlobalKey
for Form
?
Upvotes: 0
Views: 663
Reputation:
The docs are pretty self explanatory I think.
GlobalKey: A key that is unique across the entire app.
And when you create a Form
you want it to be unique, and using GlobalKey
you can identify the form.
And docs warn you to avoid GlobalKey
at multiple places, like if you are using a ListView
and you assign every children GlobalKey
, it is a bad approach, however there is no harm of using GlobalKey
if you are using it carefully.
Upvotes: 3