Commit 5a5fcb95 authored by Adam Barth's avatar Adam Barth

Scrollable sometimes pushes frames forever

We were setting a negative velocity tolerance, which never triggered because we
assume tolerances are positive numbers. Now we use a positive tolerance and
assert to catch this case in the future.

Fixes #2765
parent 7456f6ae
...@@ -444,7 +444,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> { ...@@ -444,7 +444,7 @@ abstract class ScrollableState<T extends Scrollable> extends State<T> {
Simulation _createFlingSimulation(double scrollVelocity) { Simulation _createFlingSimulation(double scrollVelocity) {
final Simulation simulation = scrollBehavior.createScrollSimulation(scrollOffset, scrollVelocity); final Simulation simulation = scrollBehavior.createScrollSimulation(scrollOffset, scrollVelocity);
if (simulation != null) { if (simulation != null) {
final double endVelocity = pixelOffsetToScrollOffset(kPixelScrollTolerance.velocity).abs() * (scrollVelocity < 0.0 ? -1.0 : 1.0); final double endVelocity = pixelOffsetToScrollOffset(kPixelScrollTolerance.velocity).abs();
final double endDistance = pixelOffsetToScrollOffset(kPixelScrollTolerance.distance).abs(); final double endDistance = pixelOffsetToScrollOffset(kPixelScrollTolerance.distance).abs();
simulation.tolerance = new Tolerance(velocity: endVelocity, distance: endDistance); simulation.tolerance = new Tolerance(velocity: endVelocity, distance: endDistance);
} }
......
...@@ -47,7 +47,7 @@ class FrictionSimulation extends Simulation { ...@@ -47,7 +47,7 @@ class FrictionSimulation extends Simulation {
double dx(double time) => _v * math.pow(_drag, time); double dx(double time) => _v * math.pow(_drag, time);
@override @override
bool isDone(double time) => dx(time).abs() < this.tolerance.velocity; bool isDone(double time) => dx(time).abs() < tolerance.velocity;
} }
class BoundedFrictionSimulation extends FrictionSimulation { class BoundedFrictionSimulation extends FrictionSimulation {
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
bool nearEqual(double a, double b, double epsilon) => bool nearEqual(double a, double b, double epsilon) {
(a > (b - epsilon)) && (a < (b + epsilon)); assert(epsilon >= 0.0);
return (a > (b - epsilon)) && (a < (b + epsilon));
}
bool nearZero(double a, double epsilon) => nearEqual(a, 0.0, epsilon); bool nearZero(double a, double epsilon) => nearEqual(a, 0.0, epsilon);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment