Skip to main content

FormFieldData

Struct FormFieldData 

Source
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>§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:

  1. When the form field is first built, initial_value determines the field’s initial state.
  2. When FormFieldStateLeaf::reset is called (either directly or by calling FormState::reset), the form field is reset to this initial_value.
§enabled: bool

Whether 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: AutovalidateMode

Used 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>

Source

pub fn new(builder: FormFieldBuilder<T>) -> FormFieldData<T>

The fields of a form field built by builder, with Dart’s defaults.

Trait Implementations§

Source§

impl<T: 'static> Debug for FormFieldData<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for FormFieldData<T>

§

impl<T> !Send for FormFieldData<T>

§

impl<T> !Sync for FormFieldData<T>

§

impl<T> !UnwindSafe for FormFieldData<T>

§

impl<T> Forget for FormFieldData<T>

§

impl<T> Freeze for FormFieldData<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&mut App, Option<T>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Option<T>)>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Fn(&mut App, Option<&T>) -> Option<String>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Option<&T>) -> Option<String>>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, String) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, String) -> Rc<dyn Widget>>>: Freeze, T: Freeze,

§

impl<T> Move for FormFieldData<T>

§

impl<T> Unpin for FormFieldData<T>
where T: Unpin, Rc<dyn Key>: Unpin, Rc<dyn Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&mut App, Option<T>)>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, *const u8 is !null: Unpin, Rc<dyn Fn(&mut App, Option<&T>) -> Option<String>>: Unpin, Rc<dyn Fn(&mut App, AnyElement, String) -> Rc<dyn Widget>>: Unpin,

§

impl<T> UnsafeUnpin for FormFieldData<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Option<T>)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Option<T>)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Option<&T>) -> Option<String>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Option<&T>) -> Option<String>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, String) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, String) -> Rc<dyn Widget>>>: UnsafeUnpin, T: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>