buildTextField method
Widget
buildTextField(
- String key,
- Widget textField(
- GlobalKey<
FormCraftTextFieldState> globalKey
- GlobalKey<
Builds a FormCraftTextField widget with the specified key and configuration.
If a field with the given key already exists, it returns the existing widget to avoid duplicates.
The key
parameter is required and must be unique.
The textField
parameter is required and must be a function that returns a FormCraftTextField widget.
Returns the created or existing FormCraftTextField widget.
Implementation
Widget buildTextField(
String key,
Widget Function(
GlobalKey<FormCraftTextFieldState> globalKey,
) textField,
) {
if (fields.keys.contains(key)) {
return _fields[key]!;
}
// Create a new global key for state management
final globalKey = GlobalKey<FormCraftTextFieldState>();
// Create the FormCraftTextField widget using the provided function
var textFieldWidget = textField(globalKey);
// Add the new widget to the internal map
_fields[key] = textFieldWidget;
// Add the new global key to the map for state management
globalKeys[key] = globalKey;
// Return the created FormCraftTextField widget
return textFieldWidget;
}