Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Scrolling

Why your ListView is slow, and the four fixes that actually work

Every Flutter team hits this. The list works fine with twenty items in development, ships, and then a user with eight hundred saved items reports that scrolling stutters and the app feels heavy. The instinct is to blame ListView , or Flutter, or the device. ListView is fine. In every slow list I have profiled, the cause was one of four things, and they are distinguishable in about ten minutes. First: find out which thread is late Before changing anything, run in profile mode on a real device and open the DevTools performance view. Each frame is drawn as two bars: UI thread long → build and layout are expensive. Your itemBuilder is doing too much. Raster thread long → painting is expensive. Shadows, blurs, opacity layers, saveLayer, large images. That distinction eliminates half the possible fixes immediately. Adding RepaintBoundary to a list whose UI thread is the bottleneck does nothing; simplifying widget structure in a list whose raster thread is saturated by a Backdro...

Custom scroll physics: making a list stop where you want it to

Scrolling is the interaction users feel most and describe least. “It feels sluggish”, “it doesn’t stop where I expect”, “it bounces wrong on Android”. Those complaints all point at one small class: ScrollPhysics . Most Flutter developers only ever meet it through the three named subclasses — BouncingScrollPhysics , ClampingScrollPhysics , NeverScrollableScrollPhysics . Underneath, it is a compact interface with four decision points, and understanding those turns “the list stops in a weird place” from a mystery into a two-line fix. What the class actually decides Method Decides applyPhysicsToUserOffset How a finger’s movement maps to scroll offset — resistance when overscrolling applyBoundaryConditions How much of a requested offset to refuse at the edges createBallisticSimulation What happens after the finger lifts: fling, settle, snap, or nothing tolerance When a simulation is considered finished Plus two properties worth knowing: shouldAcceptUserOffset (...