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>See StatefulWidget::key.
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: OptionsViewOpenDirectionDetermines 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>
impl<T: Clone + PartialEq + Display + 'static> RawAutocomplete<T>
Sourcepub 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>
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.
Sourcepub fn default_string_for_option(option: &dyn Display) -> String
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>
impl<T: Clone + PartialEq + 'static> RawAutocomplete<T>
Sourcepub 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>
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>
impl<T: Clone + PartialEq + 'static> RawAutocomplete<T>
Sourcepub fn key(self, key: KeyRef) -> RawAutocomplete<T>
pub fn key(self, key: KeyRef) -> RawAutocomplete<T>
Dart RawAutocomplete(key:).
Sourcepub fn options_view_open_direction(
self,
options_view_open_direction: OptionsViewOpenDirection,
) -> RawAutocomplete<T>
pub fn options_view_open_direction( self, options_view_open_direction: OptionsViewOpenDirection, ) -> RawAutocomplete<T>
Dart RawAutocomplete(optionsViewOpenDirection:).
Sourcepub fn display_string_for_option(
self,
display_string_for_option: impl Fn(&T) -> String + 'static,
) -> RawAutocomplete<T>
pub fn display_string_for_option( self, display_string_for_option: impl Fn(&T) -> String + 'static, ) -> RawAutocomplete<T>
Dart RawAutocomplete(displayStringForOption:).
Sourcepub fn field_view_builder(
self,
field_view_builder: impl Fn(&mut App, BuildContext, TextEditingControllerRef, FocusNodeRef, VoidCallback) -> WidgetRef + 'static,
) -> RawAutocomplete<T>
pub fn field_view_builder( self, field_view_builder: impl Fn(&mut App, BuildContext, TextEditingControllerRef, FocusNodeRef, VoidCallback) -> WidgetRef + 'static, ) -> RawAutocomplete<T>
Dart RawAutocomplete(fieldViewBuilder:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> RawAutocomplete<T>
pub fn focus_node(self, focus_node: FocusNodeRef) -> RawAutocomplete<T>
Dart RawAutocomplete(focusNode:).
Sourcepub fn on_selected(
self,
on_selected: impl Fn(&mut App, T) + 'static,
) -> RawAutocomplete<T>
pub fn on_selected( self, on_selected: impl Fn(&mut App, T) + 'static, ) -> RawAutocomplete<T>
Dart RawAutocomplete(onSelected:).
Sourcepub fn text_editing_controller(
self,
text_editing_controller: TextEditingControllerRef,
) -> RawAutocomplete<T>
pub fn text_editing_controller( self, text_editing_controller: TextEditingControllerRef, ) -> RawAutocomplete<T>
Dart RawAutocomplete(textEditingController:).
Sourcepub fn initial_value(
self,
initial_value: TextEditingValue,
) -> RawAutocomplete<T>
pub fn initial_value( self, initial_value: TextEditingValue, ) -> RawAutocomplete<T>
Dart RawAutocomplete(initialValue:).
Sourcepub fn on_field_submitted(app: &mut App, key: &GlobalKey)
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:
focus_nodeandtext_editing_controller, which describe how to create a separate field outside offield_view_builder.
Trait Implementations§
Source§impl<T: Clone + PartialEq + 'static> StatefulWidget for RawAutocomplete<T>
impl<T: Clone + PartialEq + 'static> StatefulWidget for RawAutocomplete<T>
Source§type State = RawAutocompleteState<T>
type State = RawAutocompleteState<T>
Source§fn create_state(&self) -> RawAutocompleteState<T>
fn create_state(&self) -> RawAutocompleteState<T>
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.