diff --git a/packages/flutter/lib/src/physics/spring_simulation.dart b/packages/flutter/lib/src/physics/spring_simulation.dart index b4b615a29c..a167523922 100644 --- a/packages/flutter/lib/src/physics/spring_simulation.dart +++ b/packages/flutter/lib/src/physics/spring_simulation.dart @@ -176,7 +176,7 @@ class _CriticalSolution implements _SpringSolution { ) { final double r = -spring.damping / (2.0 * spring.mass); final double c1 = distance; - final double c2 = velocity / (r * distance); + final double c2 = velocity - (r * distance); return _CriticalSolution.withArgs(r, c1, c2); } diff --git a/packages/flutter/test/physics/newton_test.dart b/packages/flutter/test/physics/newton_test.dart index a473bf70af..8b7e5d438b 100644 --- a/packages/flutter/test/physics/newton_test.dart +++ b/packages/flutter/test/physics/newton_test.dart @@ -167,19 +167,19 @@ void main() { expect(crit.isDone(0.0), false); expect(crit.x(0.0), 0.0); - expect(crit.dx(0.0), 5000.0); + expect(crit.dx(0.0), 0.0); - expect(crit.x(0.25).floor(), 458.0); - expect(crit.x(0.50).floor(), 496.0); - expect(crit.x(0.75).floor(), 499.0); + expect(crit.x(0.25).floor(), 356); + expect(crit.x(0.50).floor(), 479); + expect(crit.x(0.75).floor(), 497); - expect(crit.dx(0.25).floor(), 410); - expect(crit.dx(0.50).floor(), 33); - expect(crit.dx(0.75).floor(), 2); + expect(crit.dx(0.25).floor(), 1026); + expect(crit.dx(0.50).floor(), 168); + expect(crit.dx(0.75).floor(), 20); - expect(crit.isDone(1.50), true); expect(crit.x(1.5) > 499.0 && crit.x(1.5) < 501.0, true); expect(crit.dx(1.5) < 0.1, true /* basically within tolerance */); + expect(crit.isDone(1.60), true); }); test('overdamped_spring', () { @@ -195,6 +195,7 @@ void main() { expect(over.isDone(0.0), false); expect(over.x(0.0), 0.0); + expect(over.dx(0.0), moreOrLessEquals(0.0)); expect(over.x(0.5).floor(), 445.0); expect(over.x(1.0).floor(), 495.0); @@ -216,6 +217,8 @@ void main() { expect(under.type, SpringType.underDamped); expect(under.isDone(0.0), false); + expect(under.x(0.0), moreOrLessEquals(0.0)); + expect(under.dx(0.0), moreOrLessEquals(0.0)); // Overshot with negative velocity expect(under.x(1.0).floor(), 325);