Skip to main content

RawAutocomplete

Struct RawAutocomplete 

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

A widget for helping the user make a selection by entering some text and choosing from among a list of options.

The user’s text input is received in a field built with the field_view_builder parameter. The options to be displayed are determined using options_builder and rendered with options_view_builder.

The options view opens when the field gains focus or when the field’s text changes, as long as options_builder returns at least one option. The options view closes when the user selects an option, when there are no matching options, or when the field loses focus.

This is a core framework widget with very basic UI.

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:

  • Autocomplete, which is a Material-styled implementation that is based on RawAutocomplete.

Fields§

§key: Option<KeyRef>§field_view_builder: Option<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 this parameter is None, then a SizedBox::shrink is built instead. For how that pattern can be useful, see text_editing_controller.

§focus_node: Option<FocusNodeRef>

The FocusNode that is used for the text field.

The main purpose of this parameter is to allow the use of a separate text field located in another part of the widget tree instead of the text field built by field_view_builder. For example, it may be desirable to place the text field in the AppBar and the options below in the main body.

When following this pattern, field_view_builder can be omitted, so that a text field is not drawn where it would normally be. A separate text field can be created elsewhere, and a FocusNode and TextEditingController can be passed both to that text field and to RawAutocomplete.

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

§options_view_builder: 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 RawAutocomplete. To control whether it opens upward or downward, use options_view_open_direction.

In order to track which item is highlighted by keyboard navigation, the resulting options will be wrapped in an inherited AutocompleteHighlightedOption widget. Inside this callback, the index of the highlighted option can be obtained from AutocompleteHighlightedOption::of to display the highlighted option with a visual highlight to indicate it will be the option selected from the keyboard.

§options_view_open_direction: OptionsViewOpenDirection

Determines the direction in which to open the options view.

Defaults to OptionsViewOpenDirection::Down.

§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.

§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.

§text_editing_controller: Option<TextEditingControllerRef>

The TextEditingController that is used for the text field.

See focus_node for the split field pattern.

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

§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 + Display + 'static> RawAutocomplete<T>

Source

pub fn new( options_view_builder: impl Fn(&mut App, BuildContext, AutocompleteOnSelected<T>, &[T]) -> WidgetRef + 'static, options_builder: impl Fn(&mut App, TextEditingValue) -> Task<Vec<T>> + 'static, ) -> RawAutocomplete<T>

Create an instance of RawAutocomplete.

display_string_for_option defaults to default_string_for_option, which needs T’s Display form; an option type without one is built with new_with_display_string.

Source

pub fn default_string_for_option(option: &dyn Display) -> String

The default way to convert an option to a string in display_string_for_option.

Uses the Display form of the given option.

Source§

impl<T: Clone + PartialEq + 'static> RawAutocomplete<T>

Source

pub fn new_with_display_string( options_view_builder: impl Fn(&mut App, BuildContext, AutocompleteOnSelected<T>, &[T]) -> WidgetRef + 'static, options_builder: impl Fn(&mut App, TextEditingValue) -> Task<Vec<T>> + 'static, display_string_for_option: impl Fn(&T) -> String + 'static, ) -> RawAutocomplete<T>

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

Source§

impl<T: Clone + PartialEq + 'static> RawAutocomplete<T>

Source

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

Dart RawAutocomplete(key:).

Source

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

Dart RawAutocomplete(optionsViewOpenDirection:).

Source

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

Dart RawAutocomplete(displayStringForOption:).

Source

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

Dart RawAutocomplete(fieldViewBuilder:).

Source

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

Dart RawAutocomplete(focusNode:).

Source

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

Dart RawAutocomplete(onSelected:).

Source

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

Dart RawAutocomplete(textEditingController:).

Source

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

Dart RawAutocomplete(initialValue:).

Source

pub fn on_field_submitted(app: &mut App, key: &GlobalKey)

Calls AutocompleteFieldViewBuilder’s on_field_submitted callback for the RawAutocomplete widget indicated by the given GlobalKey.

This is not typically used unless a custom field is implemented instead of using field_view_builder. In the typical case, the on_field_submitted callback is passed via the AutocompleteFieldViewBuilder signature. When not using field_view_builder, the same callback can be called by using this associated function.

See also:

Trait Implementations§

Source§

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

Source§

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

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

impl<T: Clone + PartialEq + 'static> StatefulWidget for RawAutocomplete<T>

Source§

type State = RawAutocompleteState<T>

The state this widget creates.
Source§

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

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> RawAutocompleteState<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 as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

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 RawAutocomplete<T>

§

impl<T> !Send for RawAutocomplete<T>

§

impl<T> !Sync for RawAutocomplete<T>

§

impl<T> !UnwindSafe for RawAutocomplete<T>

§

impl<T> Forget for RawAutocomplete<T>

§

impl<T> Freeze for RawAutocomplete<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: 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, 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, *const RcInner<dyn Fn(&T) -> String> is !null: Freeze, PhantomData<RcInner<dyn Fn(&T) -> String>>: 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, &'static TextEditingControllerVTable: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl<T> Move for RawAutocomplete<T>

§

impl<T> Unpin for RawAutocomplete<T>
where Rc<dyn Key>: 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, AnyElement, Rc<dyn Fn(&mut App, T)>, &[T]) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&T) -> String>: Unpin, Rc<dyn Fn(&mut App, T)>: Unpin, Rc<dyn Fn(&mut App, TextEditingValue) -> Task<Vec<T>>>: Unpin, &'static TextEditingControllerVTable: Unpin, *const u8 is !null: Unpin,

§

impl<T> UnsafeUnpin for RawAutocomplete<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: 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, 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, *const RcInner<dyn Fn(&T) -> String> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&T) -> String>>: 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, &'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<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>