Skip to content

Make RawAutoComplete only update the text value if onSelected is null #123377

Open

Description

@caseycrogers

Use case

Right now, RawAutoComplete will update the text value when the user selects an option. The developer can control what value is set using displayStringForOption.

This system is very convoluted if you want to do something like trigger an action on selection and then clear the text field. Or if you're implementing a Twitter style @<user_name> feature where only a part of the textfield needs to be overwritten. The latter is especially messy with the current API.

Proposal

  1. If onSelected is null, no difference in behavior
  2. If onSelected is non-null, RawAutoComplete will not update the text value. The developer is expected to do so themself in the body of onSelected
  3. Remove displayStringForOption. Given the above behavior, it would be redundant.

It'd be a bit sloppier, but instead of introducing a subtle breaking change by modifying onSelected we could instead introduce another attribute with the above functionality called handleSelection or similar.

CC @justinmc as this is an extension of our Twitter conversation here: https://twitter.com/justinjmcc/status/1639116016591720450

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Mar 24, 2023
  2. caseycrogers commented on Mar 24, 2023

    @caseycrogers
    ContributorAuthor

    I found another use case that complicates things. I now think a more significant overhaul is justified here:
    I'd like to pick the currently-scrolled-to option when the user submits the text field (ie presses enter/taps the check button). As far as I can tell, this is very complicated with the current API:
    The onFieldSubmitted callback needs to know the state of optionsViewBuilder to know which option is currently hovered.

    So, my new proposal (on top of the new behavior suggested previously) is that all the non-widget tree dependent callbacks be moved into a RawAutoCompleteController and RawAutoComplete be given a controller argument.
    The RawAutoCompleteController is a change notifier that notifies on:
    Iterable<T> options, T hoveredOption or T selectedOption changing.

    RawAutoCompleteController could either extend TextEditingController or contain a TextEditingController (composition feels more appropriate here, but is a little verbose for a developer who just wants to pass in a TextEditingController). This way RawAutoComplete.textEditingController could be removed to avoid redundancy.

    hoveredOption is set by the developer from within optionsViewBuilder.
    While we're at it, maybe make options a generic? This makes it much easier to write an options builder that relies on extra state. See the following example:
    image
    The count is the total server count, NOT the locally fetched count so I have to pass in a class that implements Iterable<T> and then cast it back to my subclass in optionsViewBuilder.

    This allows the user to depend on the options state from outside of the RawAutoComplete callbacks.

    Note: I understand that this is a very large ask. I'm perfectly happy to write up an API proposal doc and write the PRs myself. But before I put in a lot of personal work I just want to know that my proposals have a decent chance of making it into flutter/flutter so that I don't waste my time.
    I did a very similar controller migration already for DraggableScrollableSheet that is now in production.

  3. added
    P3Issues that are less important to the Flutter project
    on Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions