Skip to main content

Autocomplete

Struct Autocomplete 

Source
pub struct Autocomplete<T: Clone + PartialEq + Hash + Debug + 'static> {
    pub key: Option<KeyRef>,
    pub display_string_for_option: AutocompleteOptionToString<T>,
    pub field_view_builder: AutocompleteFieldViewBuilder,
    pub focus_node: Option<FocusNodeRef>,
    pub on_selected: Option<AutocompleteOnSelected<T>>,
    pub options_builder: AutocompleteOptionsBuilder<T>,
    pub options_view_builder: Option<AutocompleteOptionsViewBuilder<T>>,
    pub options_view_open_direction: OptionsViewOpenDirection,
    pub options_max_height: f64,
    pub text_editing_controller: Option<TextEditingControllerRef>,
    pub initial_value: Option<TextEditingValue>,
}
Expand description

Creates a Material-styled autocomplete widget: a text field the user enters some text in, and a list of options to choose from.

The user’s text input is received in a field built with field_view_builder. The options to be displayed are determined using options_builder and rendered with options_view_builder, as RawAutocomplete does, which is what this widget is built upon and which contains more detailed documentation.

The type parameter T represents the type of the options. Most commonly this is a String. However, it’s also possible to use another type with a Display form, or a custom display_string_for_option. Options will be compared using ==.

See also:

  • RawAutocomplete, which is what Autocomplete is built upon, and which contains more detailed examples.

Fields§

§key: Option<KeyRef>§display_string_for_option: AutocompleteOptionToString<T>

Returns the string to display in the field when the option is selected.

This is useful when using a custom T type and the string to display is different than the string to search by.

If not provided, will use the option’s Display form.

§field_view_builder: AutocompleteFieldViewBuilder

Builds the field whose input is used to get the options.

Pass the provided TextEditingControllerRef to the field built here so that RawAutocomplete can listen for changes.

If not provided, will build a standard Material-style text field by default.

§focus_node: Option<FocusNodeRef>

The FocusNodeRef that is used for the text field.

For more information, see RawAutocomplete::focus_node.

If this parameter is not None, then text_editing_controller must also be non-None.

§on_selected: Option<AutocompleteOnSelected<T>>

Called when an option is selected by the user.

§options_builder: AutocompleteOptionsBuilder<T>

A function that returns the current selectable options objects given the current TextEditingValue.

§options_view_builder: Option<AutocompleteOptionsViewBuilder<T>>

Builds the selectable options widgets from a list of options objects.

The options are displayed floating below or above the field inside of an Overlay, not at the same place in the widget tree as Autocomplete. To control whether it opens upward or downward, use options_view_open_direction.

If not provided, will build a standard Material-style list of results by default.

§options_view_open_direction: OptionsViewOpenDirection

Determines the direction in which to open the options view.

Defaults to OptionsViewOpenDirection::Down.

§options_max_height: f64

The maximum height used for the default Material options list widget.

When options_view_builder is None, this property sets the maximum height that the options widget can occupy.

The default value is set to 200.

§text_editing_controller: Option<TextEditingControllerRef>

The TextEditingControllerRef that is used for the text field.

For more information, see RawAutocomplete::text_editing_controller.

If this parameter is not None, then focus_node must also be non-None.

§initial_value: Option<TextEditingValue>

The initial value to use for the text field.

Setting the initial value does not notify text_editing_controller’s listeners, and thus will not cause the options UI to appear.

This parameter is ignored if text_editing_controller is defined.

Implementations§

Source§

impl<T: Clone + PartialEq + Hash + Debug + Display + 'static> Autocomplete<T>

Source

pub fn new( options_builder: impl Fn(&mut App, TextEditingValue) -> Task<Vec<T>> + 'static, ) -> Autocomplete<T>

Creates an instance of Autocomplete.

display_string_for_option defaults to the option’s Display form; an option type without one is built with new_with_display_string.

Source§

impl<T: Clone + PartialEq + Hash + Debug + 'static> Autocomplete<T>

Source

pub fn new_with_display_string( options_builder: impl Fn(&mut App, TextEditingValue) -> Task<Vec<T>> + 'static, display_string_for_option: impl Fn(&T) -> String + 'static, ) -> Autocomplete<T>

Creates an instance of Autocomplete whose options are shown as display_string_for_option gives them, for an option type with or without a Display form.

Source

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

Dart Autocomplete(key:).

Source

pub fn display_string_for_option( self, display_string_for_option: impl Fn(&T) -> String + 'static, ) -> Autocomplete<T>

Dart Autocomplete(displayStringForOption:).

Source

pub fn field_view_builder( self, field_view_builder: impl Fn(&mut App, BuildContext, TextEditingControllerRef, FocusNodeRef, VoidCallback) -> WidgetRef + 'static, ) -> Autocomplete<T>

Dart Autocomplete(fieldViewBuilder:).

Source

pub fn focus_node(self, focus_node: FocusNodeRef) -> Autocomplete<T>

Dart Autocomplete(focusNode:).

Source

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

Dart Autocomplete(onSelected:).

Source

pub fn options_view_builder( self, options_view_builder: impl Fn(&mut App, BuildContext, AutocompleteOnSelected<T>, &[T]) -> WidgetRef + 'static, ) -> Autocomplete<T>

Dart Autocomplete(optionsViewBuilder:).

Source

pub fn options_view_open_direction( self, options_view_open_direction: OptionsViewOpenDirection, ) -> Autocomplete<T>

Dart Autocomplete(optionsViewOpenDirection:).

Source

pub fn options_max_height(self, options_max_height: f64) -> Autocomplete<T>

Dart Autocomplete(optionsMaxHeight:).

Source

pub fn text_editing_controller( self, text_editing_controller: TextEditingControllerRef, ) -> Autocomplete<T>

Dart Autocomplete(textEditingController:).

Source

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

Dart Autocomplete(initialValue:).

Trait Implementations§

Source§

impl<T: Clone + PartialEq + Hash + Debug + 'static> Debug for Autocomplete<T>

Source§

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

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

impl<T: Clone + PartialEq + Hash + Debug + 'static> StatelessWidget for Autocomplete<T>

Source§

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

Source§

fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. 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)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

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

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Autocomplete<T>

§

impl<T> !Send for Autocomplete<T>

§

impl<T> !Sync for Autocomplete<T>

§

impl<T> !UnwindSafe for Autocomplete<T>

§

impl<T> Forget for Autocomplete<T>

§

impl<T> Freeze for Autocomplete<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&T) -> String> is !null: Freeze, PhantomData<RcInner<dyn Fn(&T) -> String>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyTextEditingController>, Retained<AnyFocusNode>, Rc<dyn Fn(&mut App)>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyTextEditingController>, Retained<AnyFocusNode>, Rc<dyn Fn(&mut App)>) -> Rc<dyn Widget>>>: Freeze, NonZero<u32>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn Fn(&mut App, T)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, T)>>: Freeze, *const RcInner<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>>>: Freeze, &'static TextEditingControllerVTable: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl<T> Move for Autocomplete<T>

§

impl<T> Unpin for Autocomplete<T>
where Rc<dyn Key>: Unpin, Rc<dyn Fn(&T) -> String>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Retained<AnyTextEditingController>, Retained<AnyFocusNode>, Rc<dyn Fn(&mut App)>) -> Rc<dyn Widget>>: Unpin, NonZero<u32>: Unpin, &'static FocusNodeVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(&mut App, T)>: Unpin, Rc<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>>: Unpin, &'static TextEditingControllerVTable: Unpin, *const u8 is !null: Unpin,

§

impl<T> UnsafeUnpin for Autocomplete<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&T) -> String> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&T) -> String>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyTextEditingController>, Retained<AnyFocusNode>, Rc<dyn Fn(&mut App)>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<AnyTextEditingController>, Retained<AnyFocusNode>, Rc<dyn Fn(&mut App)>) -> Rc<dyn Widget>>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, T)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, T)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>>>: UnsafeUnpin, &'static TextEditingControllerVTable: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: 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<W> IntoWidget<StatelessKind> for W
where W: StatelessWidget,

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>