getFormKey method
Get a GlobalKey associated with a form attribute's form field state.
The getFormKey function is used to retrieve a GlobalKey associated with
the form field state of a specific form attribute. It ensures that a unique
GlobalKey is created and associated with the form field state for the
specified attribute. If a GlobalKey already exists for the attribute, it
returns that existing key.
Parameters:
attribute: The identifier of the form attribute for which you want to retrieve theGlobalKey.
Returns:
A GlobalKey associated with the form field state of the specified attribute.
Implementation
GlobalKey<FormFieldState> getFormKey(String attribute) {
late GlobalKey<FormFieldState> key;
if (_formKeys[attribute] == null) {
key = GlobalKey<FormFieldState>();
_formKeys[attribute] = key;
}
key = _formKeys[attribute]!;
return key;
}