pub struct FormFieldData<T: 'static> {
pub key: Option<KeyRef>,
pub builder: FormFieldBuilder<T>,
pub on_saved: Option<FormFieldSetter<T>>,
pub on_reset: Option<VoidCallback>,
pub force_error_text: Option<String>,
pub validator: Option<FormFieldValidator<T>>,
pub error_builder: Option<FormFieldErrorBuilder>,
pub initial_value: Option<T>,
pub enabled: bool,
pub autovalidate_mode: AutovalidateMode,
pub restoration_id: Option<String>,
}Expand description
The fields of Dart’s FormField<T>, which FormField and its subclasses carry under the
field form_field.
Fields§
§key: Option<KeyRef>See StatefulWidget::key.
builder: FormFieldBuilder<T>Function that returns the widget representing this form field.
It is passed the form field state as input, containing the current value and validation state of this field.
on_saved: Option<FormFieldSetter<T>>An optional method to call with the final value when the form is saved via
FormState::save.
on_reset: Option<VoidCallback>An optional method to call when the form field is reset via
FormFieldStateLeaf::reset.
force_error_text: Option<String>An optional property that forces the FormFieldState into an error state by directly
setting the FormFieldStateLeaf::error_text property without running the validator
function.
When the force_error_text property is provided, the
FormFieldStateLeaf::error_text will be set to the provided value, causing the form
field to be considered invalid and to display the error message specified.
When validator is provided,
force_error_text will override any error that it returns.
validator will not be called unless
force_error_text is None.
validator: Option<FormFieldValidator<T>>An optional method that validates an input. Returns an error string to display if the
input is invalid, or None otherwise.
The returned value is exposed by the FormFieldStateLeaf::error_text property. The
TextFormField uses this to override the InputDecoration.errorText value.
Alternating between error and normal state can cause the height of the TextFormField
to change if no other subtext decoration is set on the field. To create a field whose
height is fixed regardless of whether or not an error is displayed, either wrap the
TextFormField in a fixed height parent like SizedBox, or set the
InputDecoration.helperText parameter to a space.
error_builder: Option<FormFieldErrorBuilder>Function that returns the widget representing the error to display.
It is passed the form field validator error string as input. The resulting widget is
passed to InputDecoration.error.
If None, the validator error string is passed to InputDecoration.errorText.
initial_value: Option<T>An optional value to initialize the form field to, or None otherwise.
The initial_value affects the form field’s state in two cases:
- When the form field is first built,
initial_valuedetermines the field’s initial state. - When
FormFieldStateLeaf::resetis called (either directly or by callingFormState::reset), the form field is reset to thisinitial_value.
enabled: boolWhether the form is able to receive user input.
Defaults to true. If autovalidate_mode is not
AutovalidateMode::Disabled, the field will be auto validated. Likewise, if this field
is false, the widget will not be validated regardless of
autovalidate_mode.
autovalidate_mode: AutovalidateModeUsed to enable/disable this form field auto validation and update its error text.
If AutovalidateMode::OnUserInteraction, this FormField will only auto-validate after
its content changes. If AutovalidateMode::Always, it will auto-validate even without
user interaction. If AutovalidateMode::Disabled, auto-validation will be disabled.
Defaults to AutovalidateMode::Disabled.
restoration_id: Option<String>Restoration ID to save and restore the state of the form field.
Setting the restoration ID to a non-None value results in whether or not the form field
validation persists.
The state of this widget is persisted in a RestorationBucket claimed from the
surrounding RestorationScope using the provided restoration ID.
See also:
RestorationManager, which explains how state restoration works in Flutter.
Implementations§
Source§impl<T: 'static> FormFieldData<T>
impl<T: 'static> FormFieldData<T>
Sourcepub fn new(builder: FormFieldBuilder<T>) -> FormFieldData<T>
pub fn new(builder: FormFieldBuilder<T>) -> FormFieldData<T>
The fields of a form field built by builder, with Dart’s defaults.