Skip to content

ListView scrolling exception when item is a dynamic height web image #143817

@fyxtc

Description

@fyxtc

Steps to reproduce

The listview loads the web image, and when I scroll anywhere below (index10 in the video) and then scroll up, it scrolls right back to the beginning.Found it on my ios 16.5 and 17.3 devices at first, then realized it's the same on the dartpad.

If I use a fixed height it's fine, but I have no way of knowing the image height. If I use cacheExtent: maxFinite it's also fine, but the number of images is potentially so large that I can't use it and it will cause too much memory causing the app to crash!

I think this is a very serious problem, it's too much of an impact on the user experience

Expected results

I've used cacheExtent:1000, which shouldn't scroll back to the beginning, but should smoothly scroll to where it should be

Actual results

Scroll to the beginning

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

void main() => runApp(const CupertinoApp(home: TestListView2()));

final testUrls = List.generate(
    24,
    (index) =>
        "https://s2.baozicdn.com/scomic/fanpaidashixiongshimeimenquanshibingjiao-pikapi/0/1-i8qs/${index + 1}.jpg");

class TestListView2 extends StatelessWidget {
  const TestListView2({super.key});

  @override
  Widget build(BuildContext context) {
 return ListView.builder(
      cacheExtent: 1000,
      itemCount: testUrls.length,
      itemBuilder: (context, index) {
        return Container(
          color: Colors.white,
          child: Image.network(
            testUrls[index],
            loadingBuilder: (context, child, loadingProgress) {
              if (loadingProgress == null) {
                return Column(
                  children: [
                    child,
                    Text("index $index"),
                  ],
                );
              } else {
                return SizedBox(child: Text("loading...$index"));
              }
            },
          ),
        );
      },
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

f2-output.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.0, on macOS 13.6.1 22G313 darwin-x64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.86.2)
[!] Proxy Configuration
    ! NO_PROXY is not set
[✓] Connected device (4 available)
[✓] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: imagesLoading, displaying, rendering imagesf: scrollingViewports, list views, slivers, etc.found in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: duplicateIssue is closed as a duplicate of an existing issueteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions