Repository navigation
Commit 8a74ca8
authored
[cupertino_ui] Fix CupertinoPicker throwing when disposed during the tap-to-select animation (#13012)
Tapping an item that isn't centred starts a 300 ms tap-to-select animation, which `_CupertinoPickerState._handleChildTap` awaits and then reads `_effectiveController.selectedItem`. If the picker is disposed before that animation finishes, the controller has already been detached, so the read fails: an assertion in debug (`FixedExtentScrollController.selectedItem cannot be accessed before a scroll view is built with it.`) and `StateError: Bad state: No element` in release.
It shows up in ordinary "select, then hide" patterns — a parent that removes the picker as soon as a value changes, or a Material bottom sheet (200 ms exit) popped right after a tap. The reporter's analysis in the issue pinned it to this exact line and supplied a deterministic reproduction; credit to them.
The fix returns early after the `await` when the state is no longer mounted. Nothing after that point matters for a disposed picker — it only restores haptic bookkeeping.
The new test taps an off-centre item, removes the picker 50 ms into the animation, and pumps past the end. It fails on `main` with the assertion above and passes with the fix. The rest of `picker_test.dart` (28) and `date_picker_test.dart` (85), which covers the pickers built on top of `CupertinoPicker`, pass as well.
Fixes flutter/flutter#192135
## Pre-Review Checklist
I used AI tooling while working on this, and reviewed and tested all of it myself.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 78b120c commit 8a74ca8
3 files changed
Lines changed: 57 additions & 0 deletions
File tree
- packages/cupertino_ui
- lib/src
- pending_changelogs
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
326 | 332 | | |
327 | 333 | | |
328 | 334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
949 | 949 | | |
950 | 950 | | |
951 | 951 | | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
952 | 1000 | | |
0 commit comments