Skip to content

Autocomplete options customizability #74509

@justinmc

Description

@justinmc

The Autocomplete and RawAutocomplete widgets (design doc) allow custom options via optionsViewBuilder, but the options are always placed in an Overlay at the location of RawAutocomplete with full-screen constraints. There are many common use cases that are not possible with this arrangement:

  • Users may want the options in-line in the widget tree and not in an Overlay.
  • Users may want the options to be the same width as the field.
  • Users may want the options to be the same width as is available to the RawAutocomplete widget.
  • Users may want to the options to be positioned somewhere else in the Overlay.

I think we can allow all of these use cases by adding the overlayEntryViewBuilder parameter of the following type:

Widget Function(
  BuildContext context,
  LayerLink fieldLayerLink,
  BoxConstraints contraints,
  Size fieldSize,
  Widget child,
)

This parameter would default to the current behavior, which builds a CompositedTransformFollower at the location of the field with full screen width.

If null is explicitly passed to this parameter, then the options will be built in-line instead of in an Overlay.

If the user passes this parameter, they can use the given arguments to handle all of the remaining use cases above. fieldSize can be used to set the options' width to the width of the field. constraints is the constraints of the Autocomplete widget, so that can be used to create options that align with that point in the widget tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions