Skip to content

Conversation

@rkishan516
Copy link
Contributor

DropdownMenu throws RangeError when both filter and search are enabled because when we search for elements, we have some highlighted element, but if there is no element to highlight it tries to access 0th element is the filtered entries, but entries are empty.

Fixes #151878

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 this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@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 18, 2024
@rkishan516 rkishan516 force-pushed the dropdown-range-error branch from 8f2ee49 to a5109c9 Compare July 18, 2024 16:07
@Piinks Piinks requested a review from QuncCccccc July 18, 2024 22:14
@rkishan516 rkishan516 force-pushed the dropdown-range-error branch 2 times, most recently from 828ec84 to b4a1f79 Compare July 19, 2024 00:26
if (searchText.isEmpty || entries.isEmpty) {
return null;
}
if (currentHighlight != null && entries[currentHighlight!].label.toLowerCase().contains(searchText)) {
Copy link
Contributor

@PurplePolyhedron PurplePolyhedron Jul 19, 2024

Choose a reason for hiding this comment

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

It is still possible to have out of range error when entries reduce in size but still non-empty.
For example, highlight the second item, then enter a search that only matches a single item would cause out of range error in entries[currentHighlight!].

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch 2 times, most recently from 6942bf6 to c997c14 Compare July 20, 2024 04:28
Copy link
Contributor

@bleroux bleroux left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution.

Moving the new test just after the last one introduced in #147294 would make sense.

expect(textField.keyboardType, TextInputType.text);
});

// Regression test for https://github.com/flutter/flutter/issues/151878
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Regression test for https://github.com/flutter/flutter/issues/151878
// Regression test for https://github.com/flutter/flutter/issues/151878.

),
));

// Open the menu
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Open the menu
// Open the menu.

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch 2 times, most recently from 20afbe2 to 77bc9f1 Compare July 22, 2024 13:36
@PurplePolyhedron
Copy link
Contributor

PurplePolyhedron commented Jul 25, 2024

Sorry for the inconvenience. I think I've made a mistake in #147294. The checking of current selection should not be put in search.

After some further reading of the original code, I think search was intended to be "static"(it use the value type <T> so couldn't be made static) and agnostic about the _DropdownMenuState. So the logic regarding currentHighlight should not be put in search. Furthermore it doesn't fix the issues it intended to fix (#147253, #147516) if a custom searchCallback is provided, since it doesn't have easy access of the current highlight.

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch 2 times, most recently from 0e678ee to 5c65cde Compare July 25, 2024 07:27
Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contribution! Seems there are still some test failures. Could you help take a look:)?

} else {
currentHighlight = search(filteredEntries, _localTextEditingController!);
final bool shouldUpdateCurrentHighlight = _shouldUpdateCurrentHighlight(filteredEntries, _localTextEditingController!);
if(shouldUpdateCurrentHighlight){
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(shouldUpdateCurrentHighlight){
if (shouldUpdateCurrentHighlight){

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch 3 times, most recently from 2091d43 to dd453ca Compare July 30, 2024 03:28
@bleroux
Copy link
Contributor

bleroux commented Jul 30, 2024

@PurplePolyhedron Does this PR conflict with your work on #152378?

@PurplePolyhedron
Copy link
Contributor

PurplePolyhedron commented Jul 30, 2024

@PurplePolyhedron Does this PR conflict with your work on #152378?

Yes, there are some conflicts, #152378 removed the currentHighlight checking in search, because currentHighlight matching checks cannot be used for custom search, where we don't know the match conditions.

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch from dd453ca to 56f32e4 Compare August 2, 2024 02:41
@Piinks
Copy link
Contributor

Piinks commented Aug 14, 2024

@rkishan516 has the conflict with #152378 been resolved? Asking if this is ready for another review. :)

@rkishan516
Copy link
Contributor Author

@rkishan516 has the conflict with #152378 been resolved? Asking if this is ready for another review. :)

No, @Piinks, I am waiting for #152378 to merged and based on that I will do required changes.

@Piinks
Copy link
Contributor

Piinks commented Aug 15, 2024

Ah ok! Thank you very much for clarifying. We'll follow up on this once #152378 lands. 👍

Copy link
Contributor

@PurplePolyhedron PurplePolyhedron left a comment

Choose a reason for hiding this comment

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

I decided to no longer change the search function in #152378 (Pending review). There shouldn't be conflict any more.

Apologies for troubles.

currentHighlight = widget.searchCallback!(filteredEntries, _localTextEditingController!.text);
} else {
currentHighlight = search(filteredEntries, _localTextEditingController!);
final bool shouldUpdateCurrentHighlight = _shouldUpdateCurrentHighlight(filteredEntries, _localTextEditingController!);
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't use shouldUpdateCurrentHighlight when a searchCallback is provided, since we don't know its match condition.

@rkishan516 rkishan516 force-pushed the dropdown-range-error branch from 66dad07 to cda835c Compare August 21, 2024 14:41
@Piinks Piinks requested a review from QuncCccccc August 21, 2024 18:29
@rkishan516 rkishan516 force-pushed the dropdown-range-error branch from cda835c to b6bbbe9 Compare August 22, 2024 01:22
@QuncCccccc
Copy link
Contributor

Please let me know once this is ready to review:) Once the PR comments above are addressed and get the second approval, we are good to go!

@rkishan516
Copy link
Contributor Author

Please let me know once this is ready to review:) Once the PR comments above are addressed and get the second approval, we are good to go!

I have changed things other than the test bit.
If I don't add await tester.enterText(find.byType(TextField), '');, its still reading older value, even though just after that I am pumping new app.

@PurplePolyhedron
Copy link
Contributor

PurplePolyhedron commented Sep 10, 2024

Please let me know once this is ready to review:) Once the PR comments above are addressed and get the second approval, we are good to go!

I have changed things other than the test bit. If I don't add await tester.enterText(find.byType(TextField), '');, its still reading older value, even though just after that I am pumping new app.

Can you try to run the test on the newest version without await tester.enterText(find.byType(TextField), '')? I couldn't reproduce the issue, perhaps there was an issue in a earlier version and it has been resolved.

@bleroux
Copy link
Contributor

bleroux commented Sep 11, 2024

@rkishan516 Looking at the new diff, it looks like you applied autoformat to dropdown_menu_test.dart. Can you update the PR without this formatting change which leads to a huge diff.

@rkishan516
Copy link
Contributor Author

@rkishan516 Looking at the new diff, it looks like you applied autoformat to dropdown_menu_test.dart. Can you update the PR without this formatting change which leads to a huge diff.

Hey @bleroux, Sorry for that. I have fixed and pushed the change.

@bleroux
Copy link
Contributor

bleroux commented Sep 11, 2024

Hey @bleroux, Sorry for that. I have fixed and pushed the change.

No worry, every contributor hit this at one point 😅

Copy link
Contributor

@QuncCccccc QuncCccccc 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 contribution! Once we have the second approval, we are good to go!

Copy link
Contributor

@bleroux bleroux left a comment

Choose a reason for hiding this comment

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

LGTM!

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 11, 2024
@auto-submit auto-submit bot merged commit 04e1b17 into flutter:master Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 12, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 12, 2024
Roll Flutter from 2e221e7 to 303f222 (77 revisions)

flutter/flutter@2e221e7...303f222

2024-09-12 34871572+gmackall@users.noreply.github.com Manual roll to 48ddaf578fb0c8326d5b4b680b0f49ea72e33216 (flutter/flutter#155070)
2024-09-12 reidbaker@google.com Externalize and update onboarding instructions (flutter/flutter#154730)
2024-09-12 andrewrkolos@gmail.com when setting up the log reader for a device during `flutter run`, discard any `RPCError` thrown due to the device being disconnected (flutter/flutter#155049)
2024-09-12 98614782+auto-submit[bot]@users.noreply.github.com Reverts "iOS: update provisioning profile for 2024-2025 cert (#155052)" (flutter/flutter#155059)
2024-09-12 chris@bracken.jp iOS: update provisioning profile for 2024-2025 cert (flutter/flutter#155052)
2024-09-11 nate.w5687@gmail.com Factor out `Container` objects (flutter/flutter#153619)
2024-09-11 matanlurey@users.noreply.github.com Move (`dev/tools`), complete v0 of `native_driver` (Android) (flutter/flutter#154843)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from ade8ef293bc6 to ee5adf6d2ee1 (2 revisions) (flutter/flutter#155046)
2024-09-11 737941+loic-sharma@users.noreply.github.com Fix `flutter run` on Mac x64 hosts if Swift Package Manager is enabled (flutter/flutter#154645)
2024-09-11 engine-flutter-autoroll@skia.org Roll Packages from bb53e5d to 4c18648 (1 revision) (flutter/flutter#155033)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 4eb729b7a5c4 to ade8ef293bc6 (3 revisions) (flutter/flutter#155031)
2024-09-11 34465683+rkishan516@users.noreply.github.com fix: Dropdown menu trying to access highlight element which doesn't exist when search and filters both are enabled (flutter/flutter#151969)
2024-09-11 fluttergithubbot@gmail.com Marks Linux build_tests_3_5 to be unflaky (flutter/flutter#154993)
2024-09-11 abnhamoda@gmail.com Add 'direction' allow to 'SegmentedButton' oriented vertically (flutter/flutter#150903)
2024-09-11 fluttergithubbot@gmail.com Marks Linux build_tests_5_5 to be unflaky (flutter/flutter#154995)
2024-09-11 chingjun@google.com Update the signature of DDS launcher callback. (flutter/flutter#154949)
2024-09-11 30870216+gaaclarke@users.noreply.github.com Migrate Color.toString() test, improves `equalsIgnoringHashCodes` (flutter/flutter#154934)
2024-09-11 36861262+QuncCccccc@users.noreply.github.com Update material and cupertino localizations (flutter/flutter#154959)
2024-09-11 fluttergithubbot@gmail.com Marks Linux build_tests_1_5 to be unflaky (flutter/flutter#154991)
2024-09-11 fluttergithubbot@gmail.com Marks Linux build_tests_2_5 to be unflaky (flutter/flutter#154992)
2024-09-11 111122076+shashwatpathak98@users.noreply.github.com Fix `flutter create` warning regarding Java compatibility (flutter/flutter#152836)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 54757dab9462 to 4eb729b7a5c4 (1 revision) (flutter/flutter#155022)
2024-09-11 34871572+gmackall@users.noreply.github.com Fix java version used by `build_aar_module_test` (flutter/flutter#154967)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0a14c519ea4f to 54757dab9462 (1 revision) (flutter/flutter#155015)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 35a3171b72c5 to 0a14c519ea4f (1 revision) (flutter/flutter#154984)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from b9c0b96c3316 to 35a3171b72c5 (1 revision) (flutter/flutter#154980)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 52eeea075767 to b9c0b96c3316 (1 revision) (flutter/flutter#154976)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from a26075f9b1e6 to 52eeea075767 (1 revision) (flutter/flutter#154973)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 60c15bc0f40e to a26075f9b1e6 (6 revisions) (flutter/flutter#154969)
2024-09-11 matanlurey@users.noreply.github.com Migrate `apple-mobile-web-*` to `mobile-web-*`. (flutter/flutter#154964)
2024-09-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 8a038a6f7099 to 60c15bc0f40e (15 revisions) (flutter/flutter#154960)
2024-09-10 30870216+gaaclarke@users.noreply.github.com Adds dart fixes for Color opacity functions (flutter/flutter#154953)
2024-09-10 codefu@google.com Missing benchmarks for `foundation/all_elements_bench.dart` (flutter/flutter#154954)
2024-09-10 30870216+gaaclarke@users.noreply.github.com Update color assertions (flutter/flutter#154752)
2024-09-10 andrewrkolos@gmail.com handle EAGAIN (macOS) in ErrorHandlingProcessManager (flutter/flutter#154306)
2024-09-10 50643541+Mairramer@users.noreply.github.com fix unpack freezing app with animation duration zero  (flutter/flutter#153890)
2024-09-10 matanlurey@users.noreply.github.com Remove last `--disable-dart-dev` in `flutter/flutter`. (flutter/flutter#154948)
2024-09-10 34871572+gmackall@users.noreply.github.com Remove scheduler: luci from new `build_aar_module_test` (flutter/flutter#154945)
2024-09-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#154939)
2024-09-10 36861262+QuncCccccc@users.noreply.github.com `CupertinoSlidingSegmentedControl` update (flutter/flutter#152976)
2024-09-10 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#154933)
2024-09-10 andrewrkolos@gmail.com fix test `chrome.close can recover if getTab throws a StateError` (flutter/flutter#154889)
2024-09-10 jmccandless@google.com SearchBar context menu (flutter/flutter#154833)
2024-09-10 34871572+gmackall@users.noreply.github.com Fix `flutter build aar` for modules that use a plugin (flutter/flutter#154757)
2024-09-10 engine-flutter-autoroll@skia.org Roll Packages from b4e0fc1 to bb53e5d (4 revisions) (flutter/flutter#154926)
2024-09-10 tessertaha@gmail.com Clean up `SnackBar` inherit theme data test (flutter/flutter#154921)
...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
@rkishan516 rkishan516 deleted the dropdown-range-error branch July 26, 2025 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App 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.

DropdownMenu throws RangeError when both filter and search are enabled in latest beta and master.

5 participants