google / flutter.widgets

https://pub.dev/packages/flutter_widgets
BSD 3-Clause "New" or "Revised" License
1.36k stars 470 forks source link

ScrollablePositionedList.builder glitchy behaviour when adding items and scrolling to the new items #234

Open PaulVipond opened 3 years ago

PaulVipond commented 3 years ago

Problem description

When attaching the itemCount of a ScrollablePositionedList.builder to a StreamBuilder and using WidgetsBinding.instance.addPostFrameCallback() to scroll to the new items, the performance is very glitchy. The scrolling has a double bounce effect, is jerky and sometimes momentarily displays the wrong content. Under stress - many items per second - it's even more glitchy. By contrast, the AnimatedList scrolling is very smooth if it directly takes the place of the ScrollablePositionedList. My use case is a chat message list which could be 1000s of messages in total, but obviously ScrollablePositionedList only requests those for display.

Steps to reproduce

This happens consistently. I've created an example repro here: https://github.com/PaulVipond/listglitch.git

Notice how it displays 2 items without rebuilding the list, and every item thereafter refreshes the entire list on screen. The README gives some instructions on playing with the demo. If it is a bug, and you think you've fixed it, please stress the list out more by firing more messages in a shorter period to see how the scroll performance is affected.

It also seems to be requesting way more items than necessary - i.e. calls to itemBuilder().

Expected behavior

Smooth scrolling, with no jerkiness / refresh / double bounce. Calculated use of itemBuilder()

Actual behavior

Jerkiness / refresh / double bounce with intermittent momentary display of the wrong content. Over zealous use of itemBuilder()

Environment

Testing on Windows 10 Pro, Flutter 1.22.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision 9b2d32b605 (6 weeks ago) • 2021-01-22 14:36:39 -0800 Engine • revision 2f0af37152 Tools • Dart 2.10.5

vaibhavjoshi247 commented 2 years ago

@PaulVipond Any solution for this? I am facing the exact same issue here