Repository navigation
ReorderableListView#onReorder passes an unexpected new index #24786
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: qualityA truly polished experienceA truly polished experiencec: API breakBackwards-incompatible API changesBackwards-incompatible API changescustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.26Found to occur in 1.26Found to occur in 1.26frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Description
The ReorderableListView widget seems to passing an incorrect newIndex parameter when triggering the onReorder handler.
Steps to Reproduce
Here's a demo of the behavior as described in the below steps:
https://gist.github.com/chrislambe/b9aa44a5f3d3cc7dc6fdb24fb221982d
- Create an app with a
ReorderableListViewwidget and dummy data. - In the
onReorderhandler, print out the new index. - Drag the item in the 0 index position down until it swaps positions with the item in 1 index then, without releasing the item, drag it back to its original position and release. Note that the printed new index is
1instead of0, even though the intent was to drop the item in its original position. - Drag the item to the bottom of the list and release. Note that the new index is 1 greater than the bounds of the
childrenList.
Logs
Result of above step 3
flutter: oldIndex: 0, newIndex: 1, length: 4
Result of above step 4
flutter: oldIndex: 0, newIndex: 4, length: 4
flutter analyze
$ flutter analyze
Analyzing on_reorder_broken...
No issues found! (ran in 2.3s)
flutter doctor -v
$ flutter doctor -v
[✓] Flutter (Channel dev, v0.11.9, on Mac OS X 10.14.1 18B75, locale en-US)
• Flutter version 0.11.9 at /Applications/flutter
• Framework revision d48e6e433c (7 days ago), 2018-11-20 22:05:23 -0500
• Engine revision 5c8147450d
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /Users/chris/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
• All Android licenses accepted.
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
✗ Verify that all connected devices have been paired with this computer in Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
• ios-deploy 1.9.2
✗ ios-deploy out of date (1.9.4 is required). To upgrade with Brew:
brew upgrade ios-deploy
• CocoaPods version 1.5.3
[✓] Android Studio (version 3.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 23.2.1
• Dart plugin version 171.4424
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b08)
[✓] VS Code (version 1.29.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 2.20.0
[✓] Connected device (2 available)
• moto x4 • ZY224KS2L3 • android-arm64 • Android 8.1.0 (API 27)
• iPhone XR • F2133438-AFB5-421D-9CC0-36FD9FE97D28 • ios • iOS 12.1 (simulator)
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: qualityA truly polished experienceA truly polished experiencec: API breakBackwards-incompatible API changesBackwards-incompatible API changescustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.26Found to occur in 1.26Found to occur in 1.26frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Activity
jason-simmons commentedon Nov 30, 2018
@DaveShuckerow
Daniel-BD commentedon Oct 25, 2019
I'm having the exact same issue, almost a year after this issue was opened. I'm running stable channel, v1.9.1+hotfix.2
Is this being worked on? Seems like this widget is pretty much useless without this being fixed :)
ffeu commentedon Oct 25, 2019
There's an easy workaround.
Check this out:
https://stackoverflow.com/a/54164333/796963
fellow7000 commentedon Jan 18, 2020
Funny (not really) that more than one year later this simple bug is still in the framework,,,
Hello, Flutter Team, are you going to do anything on that?..
esDotDev commentedon Feb 19, 2020
The workaround is a pretty big hack, and still doesn't work 100%. This really needs to get fixed.
TahaTesser commentedon May 11, 2020
flutter doctor -v
Nomeleel commentedon May 11, 2020
I have same issue When use ReorderableListView dragging item from up to down, "newIndex" is incorrect.
vagaone commentedon Jun 8, 2020
I digged a bit into it. The indices in reorderable_list.dart are mainly used for the UI handling of the droppable space and don't represent the array position of the elements being dragged. But, and that is the problem, the indices are then used for the reorder callback.
A quick fix for the issue would be to decrease the endIndex if it is larger then the startIndex:
Can anyone take a look and give some thought's on that? I don't think it is a really nice solution, but it works.
22 remaining items
araruna commentedon May 28, 2021
I believe that the 'most promising' interpretation for the
newIndexshould be that it represents the old index of the item that is now after the moved item. Then, the only annoying situation seems to be when we drag an item down and then place it back, which triggers theonReorderunnecessarily...This even applies to the OP's case and seems to make sense of why sometimes this value is equal to the List's
length(which would mean that none of the items is now after the moved item).At least this is what seems to happen to me using the current version.
ronytesler commentedon Jul 12, 2021
Any working workaround on web?!
ronytesler commentedon Jul 12, 2021
will it be correct to reduce 1 from newIndex if the item was moved from a lower index?
kenthinson commentedon Jul 23, 2021
@ronytesler
This is what I'm using that seems to be working in my testing.
pitazzo commentedon Jul 27, 2021
I can't believe this bug is 2 years old
Flucadetena commentedon Sep 22, 2021
Same Issue, in my case when you move a Widget "higher" in the list, from 0 to 1, the "newIdx" comes wrong with a "+1". So instead of 1 you get 2. But when you move the widget "down" in the list, the values come wright. So my code looks like this:
banderberg commentedon Oct 14, 2021
Just discovered this bug for myself this morning. Surely the fix can't be very difficult to implement.
[-]ReorderableListView#onReorder passes an incorrect new index[/-][+]ReorderableListView#onReorder passes an unexpected new index[/+]HansMuller commentedon Feb 8, 2022
We've decided not to correct this issue because the obvious fix introduces a backwards incompatibility that can't be automatically corrected. More here: #93146 (comment)
I apologize for not resolving this quickly, when it would have been possible to just make the break.
github-actions commentedon Feb 22, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.