Skip to content

ListView.separated findChildIndexCallback doesn't take separators into account #174261

@SynSzakala

Description

@SynSzakala

Steps to reproduce

ListView.separated (as well as SliverList.separated accept findChildIndexCallback parameter which can be used to preserve the state of its children when their position change.

When this callback is implemented to return the actual item index (based on what's built by itemBuilder), the states aren't correctly preserved.

Expected results

Indices returned by findChildIndexCallback should be treated as item indices to match indices passed to itemBuilder.

Actual results

Indices returned by findChildIndexCallback are passed directly to SliverChildBuilderDelegate without taking the added separators into account. Currently, to achieve the desired behavior, indices returned by the callback need to be multiplied by 2.

Code sample

In the following example ListView's items are reordered but their states aren't preserved: https://dartpad.dev/?id=13e666900223cef2b9d89ea8f925bad0

Screenshots or Video

Logs

Flutter Doctor output

flutter doctor -v
[✓] Flutter (Channel stable, 3.35.1, on macOS 15.6.1 24G90 darwin-arm64, locale en-PL) [653ms]
    • Flutter version 3.35.1 on channel stable at /Users/jakub/fvm/versions/3.35.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 20f8274939 (8 days ago), 2025-08-14 10:53:09 -0700
    • Engine revision 1e9a811bf8
    • Dart version 3.9.0
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-lldb-debugging

[!] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc5) [2.3s]
    • Android SDK at /Users/jakub/Library/Android/sdk
    • Emulator version 35.3.11.0 (build_id 12836668) (CL:N/A)
    • Platform android-36, build-tools 36.0.0-rc5
    • Java binary at: /opt/homebrew/opt/openjdk@17/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.15+0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.2) [1,470ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [147ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed) [146ms]
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2025.2) [145ms]
    • IntelliJ at /Users/jakub/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 87.1
    • Dart plugin version 252.24322.5

[✓] Connected device (3 available) [6.7s]
    • SM A525F (mobile) • R58R60ABD8R • android-arm64  • Android 14 (API 34)
    • macOS (desktop)   • macos       • darwin-arm64   • macOS 15.6.1 24G90 darwin-arm64
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 139.0.7258.139
    ! Error: Browsing on the local area network for iPhone (Marcel). Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone (Jakob). Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [508ms]
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.found in release: 3.35Found to occur in 3.35found in release: 3.36Found to occur in 3.36frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions