44
55import 'package:flutter/gestures.dart' ;
66import 'package:flutter_test/flutter_test.dart' ;
7+ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart' ;
8+
79import 'velocity_tracker_data.dart' ;
810
911bool _withinTolerance (double actual, double expected) {
@@ -34,7 +36,7 @@ void main() {
3436 Offset (- 71.51939428321249 , 3716.7385187526947 ),
3537 ];
3638
37- test ('Velocity tracker gives expected results' , () {
39+ testWidgetsWithLeakTracking ('Velocity tracker gives expected results' , (WidgetTester tester) async {
3840 final VelocityTracker tracker = VelocityTracker .withKind (PointerDeviceKind .touch);
3941 int i = 0 ;
4042 for (final PointerEvent event in velocityEventData) {
@@ -48,7 +50,7 @@ void main() {
4850 }
4951 });
5052
51- test ('Velocity control test' , () {
53+ testWidgetsWithLeakTracking ('Velocity control test' , (WidgetTester tester) async {
5254 const Velocity velocity1 = Velocity (pixelsPerSecond: Offset (7.0 , 0.0 ));
5355 const Velocity velocity2 = Velocity (pixelsPerSecond: Offset (12.0 , 0.0 ));
5456 expect (velocity1, equals (const Velocity (pixelsPerSecond: Offset (7.0 , 0.0 ))));
@@ -60,7 +62,7 @@ void main() {
6062 expect (velocity1, hasOneLineDescription);
6163 });
6264
63- test ('Interrupted velocity estimation' , () {
65+ testWidgetsWithLeakTracking ('Interrupted velocity estimation' , (WidgetTester tester) async {
6466 // Regression test for https://github.com/flutter/flutter/pull/7510
6567 final VelocityTracker tracker = VelocityTracker .withKind (PointerDeviceKind .touch);
6668 for (final PointerEvent event in interruptedVelocityEventData) {
@@ -73,12 +75,12 @@ void main() {
7375 }
7476 });
7577
76- test ('No data velocity estimation' , () {
78+ testWidgetsWithLeakTracking ('No data velocity estimation' , (WidgetTester tester) async {
7779 final VelocityTracker tracker = VelocityTracker .withKind (PointerDeviceKind .touch);
7880 expect (tracker.getVelocity (), Velocity .zero);
7981 });
8082
81- test ('FreeScrollStartVelocityTracker.getVelocity throws when no points' , () {
83+ testWidgetsWithLeakTracking ('FreeScrollStartVelocityTracker.getVelocity throws when no points' , (WidgetTester tester) async {
8284 final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
8385 AssertionError ? exception;
8486 try {
@@ -90,7 +92,7 @@ void main() {
9092 expect (exception? .toString (), contains ('at least 1 point' ));
9193 });
9294
93- test ('FreeScrollStartVelocityTracker.getVelocity throws when the new point precedes the previous point' , () {
95+ testWidgetsWithLeakTracking ('FreeScrollStartVelocityTracker.getVelocity throws when the new point precedes the previous point' , (WidgetTester tester) async {
9496 final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
9597 AssertionError ? exception;
9698
@@ -105,7 +107,7 @@ void main() {
105107 expect (exception? .toString (), contains ('has a smaller timestamp' ));
106108 });
107109
108- test ('Estimate does not throw when there are more than 1 point' , () {
110+ testWidgetsWithLeakTracking ('Estimate does not throw when there are more than 1 point' , (WidgetTester tester) async {
109111 final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
110112 Offset position = Offset .zero;
111113 Duration time = Duration .zero;
@@ -127,7 +129,7 @@ void main() {
127129 }
128130 });
129131
130- test ('Makes consistent velocity estimates with consistent velocity' , () {
132+ testWidgetsWithLeakTracking ('Makes consistent velocity estimates with consistent velocity' , (WidgetTester tester) async {
131133 final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
132134 Offset position = Offset .zero;
133135 Duration time = Duration .zero;
@@ -144,4 +146,55 @@ void main() {
144146 }
145147 }
146148 });
149+
150+ testWidgetsWithLeakTracking ('Assume zero velocity when there are no recent samples - base VelocityTracker' , (WidgetTester tester) async {
151+ final VelocityTracker tracker = VelocityTracker .withKind (PointerDeviceKind .touch);
152+ Offset position = Offset .zero;
153+ Duration time = Duration .zero;
154+ const Offset positionDelta = Offset (0 , - 1 );
155+ const Duration durationDelta = Duration (seconds: 1 );
156+
157+ for (int i = 0 ; i < 10 ; i+= 1 ) {
158+ position += positionDelta;
159+ time += durationDelta;
160+ tracker.addPosition (time, position);
161+ }
162+ await tester.pumpAndSettle ();
163+
164+ expect (tracker.getVelocity ().pixelsPerSecond, Offset .zero);
165+ });
166+
167+ testWidgetsWithLeakTracking ('Assume zero velocity when there are no recent samples - IOS' , (WidgetTester tester) async {
168+ final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
169+ Offset position = Offset .zero;
170+ Duration time = Duration .zero;
171+ const Offset positionDelta = Offset (0 , - 1 );
172+ const Duration durationDelta = Duration (seconds: 1 );
173+
174+ for (int i = 0 ; i < 10 ; i+= 1 ) {
175+ position += positionDelta;
176+ time += durationDelta;
177+ tracker.addPosition (time, position);
178+ }
179+ await tester.pumpAndSettle ();
180+
181+ expect (tracker.getVelocity ().pixelsPerSecond, Offset .zero);
182+ });
183+
184+ testWidgetsWithLeakTracking ('Assume zero velocity when there are no recent samples - MacOS' , (WidgetTester tester) async {
185+ final MacOSScrollViewFlingVelocityTracker tracker = MacOSScrollViewFlingVelocityTracker (PointerDeviceKind .touch);
186+ Offset position = Offset .zero;
187+ Duration time = Duration .zero;
188+ const Offset positionDelta = Offset (0 , - 1 );
189+ const Duration durationDelta = Duration (seconds: 1 );
190+
191+ for (int i = 0 ; i < 10 ; i+= 1 ) {
192+ position += positionDelta;
193+ time += durationDelta;
194+ tracker.addPosition (time, position);
195+ }
196+ await tester.pumpAndSettle ();
197+
198+ expect (tracker.getVelocity ().pixelsPerSecond, Offset .zero);
199+ });
147200}
0 commit comments