-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Autocomplete and RawAutocomplete initialValue parameter #80257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autocomplete and RawAutocomplete initialValue parameter #80257
Conversation
@LongCatIsLooong could you take a look at this since @justinmc is on leave? |
@@ -811,7 +821,7 @@ class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>> | |||
@override | |||
void initState() { | |||
super.initState(); | |||
_textEditingController = widget.textEditingController ?? TextEditingController(); | |||
_textEditingController = widget.textEditingController ?? TextEditingController(text: widget.initialValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set the selection to the end of the string, or expose TextEditingValue
instead? IIRC an invalid selection can spell trouble if the text input is auto-focused (also I'm planning to stop painting the caret in RenderEditable
if an invalid selection is specified: #79607).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to expose TextEditingValue
@@ -192,6 +193,11 @@ class Autocomplete<T extends Object> extends StatelessWidget { | |||
/// default. | |||
final AutocompleteOptionsViewBuilder<T>? optionsViewBuilder; | |||
|
|||
/// The initial value to use for the text field. | |||
/// | |||
/// This parameter is ignored if [textEditingController] is defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe use a macro for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like setting the initial value does not notify textEditingController
's listeners, so the dropdown menu won't show (maybe worth documenting?)
This pull request is not suitable for automatic merging in its current state.
|
flutter/flutter#80257 is not yet available in Flutter stable.
Provides
initialValue
as a parameter forAutocomplete
andRawAutocomplete
widgets. This allows users to set the initial value of their text fields to the String provided. ForRawAutocomplete
, bothinitialValue
andtextEditingController
cannot be simultaneously defined since thetextEditingController
should have its text value defined when passed intoRawAutocomplete
rather than depending on theinitialValue
.I thought about just wiring
textEditingController
fromAutocomplete
toRawAutocomplete
, but the main purpose of that API was to support the split UI feature and that isn't a concern for theAutocomplete
widget, so having the requirement of having pass in a FocusNode along with a text editing controller doesn't make sense (a focus node is required if a text editing controller is passed in).Fixes #78179.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.