Skip to content

Conversation

@SalehTZ
Copy link
Contributor

@SalehTZ SalehTZ commented Jul 30, 2025

This PR changes the default value of RawAutocomplete.optionsViewOpenDirection from OptionsViewOpenDirection.down to OptionsViewOpenDirection.mostSpace.

When optionsViewOpenDirection is set to mostSpace, the options view will open in the direction with the most available space. This behavior is determined by comparing the space above and below the text field.

The commit also updates the logic for calculating optionsViewMaxHeight and originY to handle the new mostSpace option, and ensures that the switch statement for alignment correctly handles this new case.

auto.open.direction.mov

fixes #101620

Pre-launch Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

SalehTZ added 6 commits July 30, 2025 13:12
This commit changes the default value of `RawAutocomplete.optionsViewOpenDirection` from `OptionsViewOpenDirection.down` to `OptionsViewOpenDirection.auto`.

When `optionsViewOpenDirection` is set to `auto`, the options view will open in the direction with the most available space. This behavior is determined by comparing the space above and below the text field.

The commit also updates the logic for calculating `optionsViewMaxHeight` and `originY` to handle the new `auto` option, and ensures that the `switch` statement for `alignment` correctly handles this new case.
This commit introduces an 'auto' option for `OptionsViewOpenDirection` in the Material `Autocomplete` widget.

When `OptionsViewOpenDirection.auto` is selected, the options view will open downwards in landscape orientation and upwards in portrait orientation.

The default value for `optionsViewOpenDirection` has been changed from `down` to `auto`.
This commit adds tests to verify the behavior of `OptionsViewOpenDirection.auto` in the `RawAutocomplete` widget.

The tests ensure that when `OptionsViewOpenDirection.auto` is used:
- The options view opens downwards if there is enough space below the text field.
- The options view opens upwards if there is not enough space below but enough space above the text field.

Additionally, redundant argument values for `optionsViewOpenDirection` were removed in existing tests.
This test verifies that the options view opens in the direction with more available space when `optionsViewOpenDirection` is set to `OptionsViewOpenDirection.auto`.

It first positions the Autocomplete widget at the top and expects the options to open downwards. Then, it moves the widget to the bottom and expects the options to open upwards.
The default value for `optionsViewOpenDirection` in `Autocomplete` was incorrectly documented and tested as `OptionsViewOpenDirection.down`. This commit corrects the test to reflect the actual default value, which is `OptionsViewOpenDirection.auto`.
This commit adds a test to verify that when `optionsViewOpenDirection` is set to `OptionsViewOpenDirection.auto`, the options view opens in the direction where there is more available space.
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jul 30, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an auto option for OptionsViewOpenDirection in RawAutocomplete and Autocomplete, making it the new default. This is a great feature that improves user experience by dynamically positioning the options view. The implementation in RawAutocomplete for determining the direction based on available space is well done. However, I've found an issue in the default Material options view (_AutocompleteOptions) where a heuristic based on screen orientation is used for the auto case. This can lead to incorrect positioning of the options view in certain layouts. My review includes a detailed comment on this with a suggestion for a more robust approach.

@SalehTZ SalehTZ marked this pull request as ready for review July 31, 2025 05:28
SalehTZ added 9 commits August 3, 2025 07:51
…ion.down`

Also added a test to test when field alignment is center, in which direction options menu open
…me space

If both directions have the same available space, then `OptionsViewOpenDirection.down` will be selected.
…n.auto' into feat/add-OptionsViewOpenDirection.auto

# Conflicts:
#	packages/flutter/lib/src/widgets/autocomplete.dart
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the PR.

@victorsanni victorsanni requested a review from justinmc August 4, 2025 18:51
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I was questioning your approach of placing the options on the side with the most space, but after some thought I think you're probably right...

Context menus do something slightly different. They try to position themselves above the content, and if they don't fit, then they position themselves below (see TextSelectionToolbarLayoutDelegate). Maybe this approach doesn't make sense for Autocomplete because the size of the options changes? It would be strange for the options to flip from above to below as the user types and gets different numbers of options.

However, what about the case where the Autocomplete is in a vertical scrollable? I guess if you scroll while the options are visible then they will flip between top and bottom at the middle of the screen. Maybe this is what they should do, though.

@LongCatIsLooong
Copy link
Contributor

LGTM with one documentation nit

@SalehTZ SalehTZ changed the title feat: add OptionsViewOpenDirection.auto to RawAutocomplete feat: add OptionsViewOpenDirection.mostSpace to RawAutocomplete Oct 9, 2025
@SalehTZ
Copy link
Contributor Author

SalehTZ commented Oct 11, 2025

I hope everything is done 👍🏻

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 15, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 15, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 15, 2025

autosubmit label was removed for flutter/flutter/172997, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 15, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Oct 16, 2025
Merged via the queue into flutter:master with commit 908eab5 Oct 16, 2025
76 of 77 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 16, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 16, 2025
…10244)

Manual roll requested by [email protected]

flutter/flutter@7cd821c...a873a27

2025-10-16 [email protected] [tool] makes listing a shader also as an asset a build failure (flutter/flutter#176866)
2025-10-16 [email protected] Roll Packages from d062181 to 835dccb (7 revisions) (flutter/flutter#177100)
2025-10-16 [email protected] Handle the new location of Perfetto in create_updated_flutter_deps.py (flutter/flutter#177099)
2025-10-16 [email protected] Implement dialog windows for the win32 platform (flutter/flutter#176309)
2025-10-16 [email protected] `SelectableRegion` should not show flutter rendered context menu when web context menu is enabled (flutter/flutter#176855)
2025-10-16 [email protected] Manual roll Skia to 2d9df7c70b6f (flutter/flutter#177074)
2025-10-16 [email protected] feat: add `OptionsViewOpenDirection.mostSpace` to `RawAutocomplete` (flutter/flutter#172997)
2025-10-16 [email protected] [Android] Refactor `ImageReaderSurfaceProducer` restoration after app resumes (flutter/flutter#175937)
2025-10-15 [email protected] Refactor: migrate fade upwards page transition builder to widgets (flutter/flutter#175560)
2025-10-15 [email protected] Marks Windows windowing_test to be unflaky (flutter/flutter#176701)
2025-10-15 [email protected] fix: 🐛 Add equality and hashCode implementations to ScrollAwareImageProvider (flutter/flutter#175038)
2025-10-15 [email protected] Updates `sliver_tree.1.dart‎` to use `MediaQuery.widthOf(context)`  (flutter/flutter#176888)
2025-10-15 [email protected] [web] Fix focus issues in newer versions of Chrome (flutter/flutter#176938)
2025-10-15 [email protected] [Android 16] Update `android_engine_vulkan_tests` to Test Against SDK 36 Emulator (flutter/flutter#176985)
2025-10-15 [email protected] Fix key events interception by RadioGroup when no Radio is focused. (flutter/flutter#176335)
2025-10-15 [email protected] Update cherry-pick instructions to include instructions for pre-release CPs (flutter/flutter#177020)
2025-10-15 [email protected] Manual roll Skia to c501c727a007 (flutter/flutter#177015)
2025-10-15 [email protected] Update examples to latest Linux runner style (flutter/flutter#177033)
2025-10-15 [email protected] [material/menu_anchor.dart] Create internal menu controller if external controller is changed to null. (flutter/flutter#176375)
2025-10-15 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix - TalkBack does not announce list information (#174374)" (flutter/flutter#177062)
2025-10-14 [email protected] Implement Regular Windows for Linux (flutter/flutter#176187)
2025-10-14 [email protected] Fix - TalkBack does not announce list information (flutter/flutter#174374)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…lutter#172997)

This PR changes the default value of
`RawAutocomplete.optionsViewOpenDirection` from
`OptionsViewOpenDirection.down` to `OptionsViewOpenDirection.mostSpace`.

When `optionsViewOpenDirection` is set to `mostSpace`, the options view
will open in the direction with the most available space. This behavior
is determined by comparing the space above and below the text field.

The commit also updates the logic for calculating `optionsViewMaxHeight`
and `originY` to handle the new `mostSpace` option, and ensures that the
`switch` statement for `alignment` correctly handles this new case.



https://github.com/user-attachments/assets/8e00318a-bd07-402b-b516-543740cd5c26



fixes flutter#101620 


## Pre-launch Checklist

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

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Signed-off-by: Alex Tz <[email protected]>
Co-authored-by: Victor Sanni <[email protected]>
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 should automatically place options above or below based on where fits

5 participants