Skip to main content

FormField

Struct FormField 

Source
pub struct FormField<T>
where T: 'static,
{ /* private fields */ }
Expand description

A single form field.

This widget maintains the current state of the form field, so that updates and validation errors are visually reflected in the UI.

When used inside a Form, you can use methods on FormState to query or manipulate the form data as a whole. For example, calling FormState::save will invoke each FormField’s on_saved callback in turn.

Use a GlobalKey with FormField if you want to retrieve its current state, for example if you want one form field to depend on another.

A Form ancestor is not required. The Form allows one to save, reset, or validate multiple fields at once. To use without a Form, pass a GlobalKey to the constructor and use GlobalKey::current_state to save or reset the form field.

See also:

  • Form, which is the widget that aggregates the form fields.
  • TextField, which is a commonly used form field for entering text.

Implementations§

Source§

impl<T> FormField<T>
where T: Clone + 'static,

Source

pub fn new( builder: impl Fn(&mut App, AnyFormFieldState<T>) -> Rc<dyn Widget> + 'static, ) -> FormField<T>

Creates a single form field.

Source

pub fn key(self, key: KeyRef) -> FormField<T>

Dart FormField(key:).

Source

pub fn on_saved( self, on_saved: impl Fn(&mut App, Option<T>) + 'static, ) -> FormField<T>

Dart FormField(onSaved:).

Source

pub fn on_reset(self, on_reset: impl Fn(&mut App) + 'static) -> FormField<T>

Dart FormField(onReset:).

Source

pub fn force_error_text( self, force_error_text: impl Into<String>, ) -> FormField<T>

Dart FormField(forceErrorText:).

Source

pub fn validator( self, validator: impl Fn(&mut App, Option<&T>) -> Option<String> + 'static, ) -> FormField<T>

Dart FormField(validator:).

Source

pub fn error_builder( self, error_builder: impl Fn(&mut App, AnyElement, String) -> Rc<dyn Widget> + 'static, ) -> FormField<T>

Dart FormField(errorBuilder:).

Source

pub fn initial_value(self, initial_value: T) -> FormField<T>

Dart FormField(initialValue:).

Source

pub fn enabled(self, enabled: bool) -> FormField<T>

Dart FormField(enabled:).

Source

pub fn autovalidate_mode( self, autovalidate_mode: AutovalidateMode, ) -> FormField<T>

Dart FormField(autovalidateMode:).

Source

pub fn restoration_id(self, restoration_id: impl Into<String>) -> FormField<T>

Dart FormField(restorationId:).

Trait Implementations§

Source§

impl<T> Debug for FormField<T>
where T: 'static,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> FormFieldLeaf for FormField<T>
where T: Clone + 'static,

Source§

type Value = T

Dart’s T of FormField<T>.
Source§

fn form_field_data( &self, ) -> &FormFieldData<<FormField<T> as FormFieldLeaf>::Value>

Source§

impl<T> StatefulWidget for FormField<T>
where T: Clone + 'static,

Source§

type State = FormFieldState<T>

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> FormFieldState<T>

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for FormField<T>

§

impl<T> !Send for FormField<T>

§

impl<T> !Sync for FormField<T>

§

impl<T> !UnwindSafe for FormField<T>

§

impl<T> Forget for FormField<T>

§

impl<T> Freeze for FormField<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 FormField<T>

§

impl<T> Unpin for FormField<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 FormField<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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
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>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more