这是indexloc提供的服务,不要输入任何密码
Skip to content

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

Merged

Conversation

shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Apr 12, 2021

Provides initialValue as a parameter for Autocomplete and RawAutocomplete widgets. This allows users to set the initial value of their text fields to the String provided. For RawAutocomplete, both initialValue and textEditingController cannot be simultaneously defined since the textEditingController should have its text value defined when passed into RawAutocomplete rather than depending on the initialValue.

I thought about just wiring textEditingController from Autocomplete to RawAutocomplete, but the main purpose of that API was to support the split UI feature and that isn't a concern for the Autocomplete 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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 12, 2021
@google-cla google-cla bot added the cla: yes label Apr 12, 2021
@shihaohong
Copy link
Contributor Author

@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);
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor

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?)

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux docs has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite docs-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot merged commit 884129d into flutter:master Apr 14, 2021
@shihaohong shihaohong deleted the autocomplete-initial-value branch April 19, 2021 03:46
jpnurmi added a commit to jpnurmi/ubuntu-desktop-installer that referenced this pull request Sep 2, 2021
flutter/flutter#80257 is not yet available in
Flutter stable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] Expose Autocomplete.textEditingController parameter like RawAutocomplete
3 participants