Junior — Middle
What are the different types of indexes used in databases?
sobes.tech AI
Answer from AI
In Flutter, a global key (GlobalKey) is a unique identifier that allows access to a widget's state from anywhere in the application.
Typically, keys are used to manage state and identify widgets in the widget tree. Unlike local keys, a global key guarantees uniqueness across the entire app and allows:
- Access to the widget's state via
globalKey.currentState. - Managing navigation and interacting with widgets outside the current context.
Example usage:
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Form(
key: _formKey,
child: TextFormField(...),
);
// Later, you can check the validity of the form
if (_formKey.currentState!.validate()) {
// Data is valid
}
Thus, a global key helps manage state and interact with widgets without having direct access to their context.