@@ -260,8 +260,6 @@ class _PageListViewportGesturesState extends State<PageListViewportGestures> wit
260
260
}
261
261
}
262
262
263
- Duration ? lastDuration;
264
-
265
263
void _onFrictionTick (Duration elapsedTime) {
266
264
if (elapsedTime == Duration .zero) {
267
265
return ;
@@ -314,8 +312,16 @@ class _PageListViewportGesturesState extends State<PageListViewportGestures> wit
314
312
}
315
313
316
314
class DeprecatedPanAndScaleVelocityTracker {
317
- static double kViewportMinFlingVelocity = 600 ;
318
- static double kViewportMinFlingDistance = 60 ;
315
+ /// The maximum velocity a gesture can have and still be considered a viewport
316
+ /// re-adjustment. Used in tandem with the [kViewportReAdjustmentMinTranslationDistance]
317
+ /// to determine if the user is re-adjusting the viewport. Viewport re-adjustments
318
+ /// result in the momentum simulation to be aborted.
319
+ static double kViewportReAdjustmentMaxVelocity = 600 ;
320
+
321
+ /// The minimum distance the viewport must be translated such that the
322
+ /// gesture is considered a viewport re-adjustment which results in the
323
+ /// momentum simulation to be aborted.
324
+ static double kViewportReAdjustmentMinTranslationDistance = 60 ;
319
325
320
326
DeprecatedPanAndScaleVelocityTracker ({
321
327
required Clock clock,
@@ -333,7 +339,11 @@ class DeprecatedPanAndScaleVelocityTracker {
333
339
334
340
Offset get velocity => _launchVelocity;
335
341
Offset _launchVelocity = Offset .zero;
336
- Offset _startPosition = Offset .zero;
342
+
343
+ /// The focal point when the gesture started.
344
+ Offset _startFocalPosition = Offset .zero;
345
+
346
+ /// The last focal point before the gesture ended
337
347
Offset _lastFocalPosition = Offset .zero;
338
348
339
349
void onScaleStart (ScaleStartDetails details) {
@@ -378,7 +388,7 @@ class DeprecatedPanAndScaleVelocityTracker {
378
388
}
379
389
380
390
_previousPointerCount = details.pointerCount;
381
- _startPosition = details.localFocalPoint;
391
+ _startFocalPosition = details.localFocalPoint;
382
392
}
383
393
384
394
void onScaleUpdate (Offset localFocalPoint, int pointerCount) {
@@ -443,8 +453,9 @@ class DeprecatedPanAndScaleVelocityTracker {
443
453
return ;
444
454
}
445
455
446
- final translationDistance = (_lastFocalPosition - _startPosition).distance;
447
- if (translationDistance > kViewportMinFlingDistance && velocity.distance < kViewportMinFlingVelocity) {
456
+ final translationDistance = (_lastFocalPosition - _startFocalPosition).distance;
457
+ if (translationDistance > kViewportReAdjustmentMinTranslationDistance &&
458
+ velocity.distance < kViewportReAdjustmentMaxVelocity) {
448
459
// The user was readjusting the viewport by dragging it to the
449
460
// new position.
450
461
return ;
@@ -471,6 +482,11 @@ class DeprecatedPanAndScaleVelocityTracker {
471
482
}
472
483
473
484
class PanningFrictionSimulation {
485
+ // Dampening factors applied to each component of a [FrictionSimulation].
486
+ // Larger values result in the [FrictionSimulation] to accelerate faster and approach
487
+ // zero slower, giving the impression of the simulation being "more slippery".
488
+ // It was found through testing that other scroll systems seem to be use different dampening
489
+ // factors for the vertical and horizontal components.
474
490
static const kVerticalDrag = 0.095 ;
475
491
static const kHorizontalDrag = 0.0425 ;
476
492
@@ -479,7 +495,8 @@ class PanningFrictionSimulation {
479
495
required Offset velocity,
480
496
}) : _position = position,
481
497
_velocity = velocity {
482
- // Clamping bounds determines how long the simulation will run. Larger numbers slide for longer,
498
+ // Clamping bounds enforces a maximum instantaneous velocity of the viewport
499
+ // and in turn, how long the simulation will run. Larger numbers slide for longer,
483
500
// smaller numbers end more quickly.
484
501
_xSimulation = ClampedSimulation (
485
502
FrictionSimulation (
@@ -506,7 +523,7 @@ class PanningFrictionSimulation {
506
523
// near the end (when it smoothly slides to zero).
507
524
constantDeceleration: 2.35 ,
508
525
),
509
- dxMin: - 2000 , // Scroll up more slowly than scrolling down . A config found in some other scrolling systems.
526
+ dxMin: - 2000 , // Scroll down more slowly than scrolling up . A config found in some other scrolling systems.
510
527
dxMax: 3000 ,
511
528
);
512
529
}
0 commit comments