From 5a5fcb959dbe35bde7b141d09f61ed09f3e06563 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 21 Mar 2016 12:21:24 -0700 Subject: [PATCH] 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 --- packages/flutter/lib/src/widgets/scrollable.dart | 2 +- packages/newton/lib/src/friction_simulation.dart | 2 +- packages/newton/lib/src/utils.dart | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index d189c2d40c..14f8559d53 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -444,7 +444,7 @@ abstract class ScrollableState extends State { Simulation _createFlingSimulation(double scrollVelocity) { final Simulation simulation = scrollBehavior.createScrollSimulation(scrollOffset, scrollVelocity); 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(); simulation.tolerance = new Tolerance(velocity: endVelocity, distance: endDistance); } diff --git a/packages/newton/lib/src/friction_simulation.dart b/packages/newton/lib/src/friction_simulation.dart index d663e660e6..195865500b 100644 --- a/packages/newton/lib/src/friction_simulation.dart +++ b/packages/newton/lib/src/friction_simulation.dart @@ -47,7 +47,7 @@ class FrictionSimulation extends Simulation { double dx(double time) => _v * math.pow(_drag, time); @override - bool isDone(double time) => dx(time).abs() < this.tolerance.velocity; + bool isDone(double time) => dx(time).abs() < tolerance.velocity; } class BoundedFrictionSimulation extends FrictionSimulation { diff --git a/packages/newton/lib/src/utils.dart b/packages/newton/lib/src/utils.dart index 24a5e11d38..b66bb46ea2 100644 --- a/packages/newton/lib/src/utils.dart +++ b/packages/newton/lib/src/utils.dart @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -bool nearEqual(double a, double b, double epsilon) => - (a > (b - epsilon)) && (a < (b + epsilon)); +bool nearEqual(double a, double b, double epsilon) { + assert(epsilon >= 0.0); + return (a > (b - epsilon)) && (a < (b + epsilon)); +} bool nearZero(double a, double epsilon) => nearEqual(a, 0.0, epsilon);