scroll_activity.dart 22.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
6
import 'dart:math' as math;
7 8 9 10 11 12 13 14 15 16

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';

import 'basic.dart';
import 'framework.dart';
import 'scroll_metrics.dart';
import 'scroll_notification.dart';

17 18
/// A backend for a [ScrollActivity].
///
19
/// Used by subclasses of [ScrollActivity] to manipulate the scroll view that
20 21 22 23 24
/// they are acting upon.
///
/// See also:
///
///  * [ScrollActivity], which uses this class as its delegate.
25
///  * [ScrollPositionWithSingleContext], the main implementation of this interface.
26
abstract class ScrollActivityDelegate {
27
  /// The direction in which the scroll view scrolls.
28 29
  AxisDirection get axisDirection;

30 31 32 33
  /// Update the scroll position to the given pixel value.
  ///
  /// Returns the overscroll, if any. See [ScrollPosition.setPixels] for more
  /// information.
34
  double setPixels(double pixels);
35 36 37 38 39 40 41

  /// Updates the scroll position by the given amount.
  ///
  /// Appropriate for when the user is directly manipulating the scroll
  /// position, for example by dragging the scroll view. Typically applies
  /// [ScrollPhysics.applyPhysicsToUserOffset] and other transformations that
  /// are appropriate for user-driving scrolling.
42
  void applyUserOffset(double delta);
43

44
  /// Terminate the current activity and start an idle activity.
45
  void goIdle();
46 47 48

  /// Terminate the current activity and start a ballistic activity with the
  /// given velocity.
49 50 51 52 53 54 55
  void goBallistic(double velocity);
}

/// Base class for scrolling activities like dragging and flinging.
///
/// See also:
///
56 57
///  * [ScrollPosition], which uses [ScrollActivity] objects to manage the
///    [ScrollPosition] of a [Scrollable].
58
abstract class ScrollActivity {
59
  /// Initializes [delegate] for subclasses.
60 61
  ScrollActivity(this._delegate);

62
  /// The delegate that this activity will use to actuate the scroll view.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  ScrollActivityDelegate get delegate => _delegate;
  ScrollActivityDelegate _delegate;

  /// Updates the activity's link to the [ScrollActivityDelegate].
  ///
  /// This should only be called when an activity is being moved from a defunct
  /// (or about-to-be defunct) [ScrollActivityDelegate] object to a new one.
  void updateDelegate(ScrollActivityDelegate value) {
    assert(_delegate != value);
    _delegate = value;
  }

  /// Called by the [ScrollActivityDelegate] when it has changed type (for
  /// example, when changing from an Android-style scroll position to an
  /// iOS-style scroll position). If this activity can differ between the two
  /// modes, then it should tell the position to restart that activity
  /// appropriately.
  ///
  /// For example, [BallisticScrollActivity]'s implementation calls
  /// [ScrollActivityDelegate.goBallistic].
  void resetActivity() { }

85
  /// Dispatch a [ScrollStartNotification] with the given metrics.
86
  void dispatchScrollStartNotification(ScrollMetrics metrics, BuildContext? context) {
87
    ScrollStartNotification(metrics: metrics, context: context).dispatch(context);
88 89
  }

90
  /// Dispatch a [ScrollUpdateNotification] with the given metrics and scroll delta.
91
  void dispatchScrollUpdateNotification(ScrollMetrics metrics, BuildContext context, double scrollDelta) {
92
    ScrollUpdateNotification(metrics: metrics, context: context, scrollDelta: scrollDelta).dispatch(context);
93 94
  }

95
  /// Dispatch an [OverscrollNotification] with the given metrics and overscroll.
96
  void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) {
97
    OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll).dispatch(context);
98 99
  }

100
  /// Dispatch a [ScrollEndNotification] with the given metrics and overscroll.
101
  void dispatchScrollEndNotification(ScrollMetrics metrics, BuildContext context) {
102
    ScrollEndNotification(metrics: metrics, context: context).dispatch(context);
103 104
  }

105
  /// Called when the scroll view that is performing this activity changes its metrics.
106 107
  void applyNewDimensions() { }

108 109
  /// Whether the scroll view should ignore pointer events while performing this
  /// activity.
110 111 112 113 114
  ///
  /// See also:
  ///
  ///  * [isScrolling], which describes whether the activity is considered
  ///    to represent user interaction or not.
115 116
  bool get shouldIgnorePointer;

117 118
  /// Whether performing this activity constitutes scrolling.
  ///
119 120
  /// Used, for example, to determine whether the user scroll
  /// direction (see [ScrollPosition.userScrollDirection]) is
121
  /// [ScrollDirection.idle].
122 123 124 125 126 127
  ///
  /// See also:
  ///
  ///  * [shouldIgnorePointer], which controls whether pointer events
  ///    are allowed while the activity is live.
  ///  * [UserScrollNotification], which exposes this status.
128 129
  bool get isScrolling;

130 131 132 133 134
  /// If applicable, the velocity at which the scroll offset is currently
  /// independently changing (i.e. without external stimuli such as a dragging
  /// gestures) in logical pixels per second for this activity.
  double get velocity;

135
  /// Called when the scroll view stops performing this activity.
136
  @mustCallSuper
137
  void dispose() { }
138 139

  @override
140
  String toString() => describeIdentity(this);
141 142
}

143 144 145
/// A scroll activity that does nothing.
///
/// When a scroll view is not scrolling, it is performing the idle activity.
146 147 148
///
/// If the [Scrollable] changes dimensions, this activity triggers a ballistic
/// activity to restore the view.
149
class IdleScrollActivity extends ScrollActivity {
150
  /// Creates a scroll activity that does nothing.
151
  IdleScrollActivity(super.delegate);
152 153 154 155 156 157 158 159 160 161 162

  @override
  void applyNewDimensions() {
    delegate.goBallistic(0.0);
  }

  @override
  bool get shouldIgnorePointer => false;

  @override
  bool get isScrolling => false;
163 164 165

  @override
  double get velocity => 0.0;
166 167
}

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
/// Interface for holding a [Scrollable] stationary.
///
/// An object that implements this interface is returned by
/// [ScrollPosition.hold]. It holds the scrollable stationary until an activity
/// is started or the [cancel] method is called.
abstract class ScrollHoldController {
  /// Release the [Scrollable], potentially letting it go ballistic if
  /// necessary.
  void cancel();
}

/// A scroll activity that does nothing but can be released to resume
/// normal idle behavior.
///
/// This is used while the user is touching the [Scrollable] but before the
/// touch has become a [Drag].
///
/// For the purposes of [ScrollNotification]s, this activity does not constitute
/// scrolling, and does not prevent the user from interacting with the contents
/// of the [Scrollable] (unlike when a drag has begun or there is a scroll
/// animation underway).
class HoldScrollActivity extends ScrollActivity implements ScrollHoldController {
  /// Creates a scroll activity that does nothing.
  HoldScrollActivity({
192
    required ScrollActivityDelegate delegate,
193 194 195 196
    this.onHoldCanceled,
  }) : super(delegate);

  /// Called when [dispose] is called.
197
  final VoidCallback? onHoldCanceled;
198 199 200 201 202 203 204

  @override
  bool get shouldIgnorePointer => false;

  @override
  bool get isScrolling => false;

205 206 207
  @override
  double get velocity => 0.0;

208 209 210 211 212 213 214
  @override
  void cancel() {
    delegate.goBallistic(0.0);
  }

  @override
  void dispose() {
215
    onHoldCanceled?.call();
216 217 218 219
    super.dispose();
  }
}

220 221 222 223 224 225
/// Scrolls a scroll view as the user drags their finger across the screen.
///
/// See also:
///
///  * [DragScrollActivity], which is the activity the scroll view performs
///    while a drag is underway.
226
class ScrollDragController implements Drag {
227 228 229 230 231
  /// Creates an object that scrolls a scroll view as the user drags their
  /// finger across the screen.
  ///
  /// The [delegate] and `details` arguments must not be null.
  ScrollDragController({
232 233
    required ScrollActivityDelegate delegate,
    required DragStartDetails details,
234
    this.onDragCanceled,
235
    this.carriedVelocity,
236
    this.motionStartDistanceThreshold,
237
  }) : assert(
238
         motionStartDistanceThreshold == null || motionStartDistanceThreshold > 0.0,
239
         'motionStartDistanceThreshold must be a positive number or null',
240
       ),
241
       _delegate = delegate,
242 243
       _lastDetails = details,
       _retainMomentum = carriedVelocity != null && carriedVelocity != 0.0,
244
       _lastNonStationaryTimestamp = details.sourceTimeStamp,
245
       _kind = details.kind,
246
       _offsetSinceLastStop = motionStartDistanceThreshold == null ? null : 0.0;
247

248
  /// The object that will actuate the scroll view as the user drags.
249 250
  ScrollActivityDelegate get delegate => _delegate;
  ScrollActivityDelegate _delegate;
251

252
  /// Called when [dispose] is called.
253
  final VoidCallback? onDragCanceled;
254

255 256
  /// Velocity that was present from a previous [ScrollActivity] when this drag
  /// began.
257
  final double? carriedVelocity;
258

259 260
  /// Amount of pixels in either direction the drag has to move by to start
  /// scroll movement again after each time scrolling came to a stop.
261
  final double? motionStartDistanceThreshold;
262

263
  Duration? _lastNonStationaryTimestamp;
264
  bool _retainMomentum;
265
  /// Null if already in motion or has no [motionStartDistanceThreshold].
266
  double? _offsetSinceLastStop;
267 268 269 270

  /// Maximum amount of time interval the drag can have consecutive stationary
  /// pointer update events before losing the momentum carried from a previous
  /// scroll activity.
271
  static const Duration momentumRetainStationaryDurationThreshold =
272
      Duration(milliseconds: 20);
273

274 275 276 277
  /// The minimum amount of velocity needed to apply the [carriedVelocity] at
  /// the end of a drag. Expressed as a factor. For example with a
  /// [carriedVelocity] of 2000, we will need a velocity of at least 1000 to
  /// apply the [carriedVelocity] as well. If the velocity does not meet the
278
  /// threshold, the [carriedVelocity] is lost. Decided by fair eyeballing
279 280 281
  /// with the scroll_overlay platform test.
  static const double momentumRetainVelocityThresholdFactor = 0.5;

282 283 284 285
  /// Maximum amount of time interval the drag can have consecutive stationary
  /// pointer update events before needing to break the
  /// [motionStartDistanceThreshold] to start motion again.
  static const Duration motionStoppedDurationThreshold =
286
      Duration(milliseconds: 50);
287

288 289
  /// The drag distance past which, a [motionStartDistanceThreshold] breaking
  /// drag is considered a deliberate fling.
290
  static const double _bigThresholdBreakDistance = 24.0;
291

292 293
  bool get _reversed => axisDirectionIsReversed(delegate.axisDirection);

294 295 296 297 298 299 300 301 302
  /// Updates the controller's link to the [ScrollActivityDelegate].
  ///
  /// This should only be called when a controller is being moved from a defunct
  /// (or about-to-be defunct) [ScrollActivityDelegate] object to a new one.
  void updateDelegate(ScrollActivityDelegate value) {
    assert(_delegate != value);
    _delegate = value;
  }

303 304
  /// Determines whether to lose the existing incoming velocity when starting
  /// the drag.
305
  void _maybeLoseMomentum(double offset, Duration? timestamp) {
306 307 308
    if (_retainMomentum &&
        offset == 0.0 &&
        (timestamp == null || // If drag event has no timestamp, we lose momentum.
309
         timestamp - _lastNonStationaryTimestamp! > momentumRetainStationaryDurationThreshold)) {
310 311 312 313 314
      // If pointer is stationary for too long, we lose momentum.
      _retainMomentum = false;
    }
  }

315 316 317
  /// If a motion start threshold exists, determine whether the threshold needs
  /// to be broken to scroll. Also possibly apply an offset adjustment when
  /// threshold is first broken.
318
  ///
319 320
  /// Returns `0.0` when stationary or within threshold. Returns `offset`
  /// transparently when already in motion.
321
  double _adjustForScrollStartThreshold(double offset, Duration? timestamp) {
322 323 324
    if (timestamp == null) {
      // If we can't track time, we can't apply thresholds.
      // May be null for proxied drags like via accessibility.
325
      return offset;
326 327 328 329
    }
    if (offset == 0.0) {
      if (motionStartDistanceThreshold != null &&
          _offsetSinceLastStop == null &&
330
          timestamp - _lastNonStationaryTimestamp! > motionStoppedDurationThreshold) {
331 332 333 334
        // Enforce a new threshold.
        _offsetSinceLastStop = 0.0;
      }
      // Not moving can't break threshold.
335
      return 0.0;
336 337
    } else {
      if (_offsetSinceLastStop == null) {
338 339 340
        // Already in motion or no threshold behavior configured such as for
        // Android. Allow transparent offset transmission.
        return offset;
341
      } else {
342 343
        _offsetSinceLastStop = _offsetSinceLastStop! + offset;
        if (_offsetSinceLastStop!.abs() > motionStartDistanceThreshold!) {
344 345
          // Threshold broken.
          _offsetSinceLastStop = null;
346
          if (offset.abs() > _bigThresholdBreakDistance) {
347 348 349 350 351 352 353 354
            // This is heuristically a very deliberate fling. Leave the motion
            // unaffected.
            return offset;
          } else {
            // This is a normal speed threshold break.
            return math.min(
              // Ease into the motion when the threshold is initially broken
              // to avoid a visible jump.
355
              motionStartDistanceThreshold! / 3.0,
356
              offset.abs(),
357 358
            ) * offset.sign;
          }
359
        } else {
360
          return 0.0;
361 362 363 364 365
        }
      }
    }
  }

366 367 368 369
  @override
  void update(DragUpdateDetails details) {
    assert(details.primaryDelta != null);
    _lastDetails = details;
370
    double offset = details.primaryDelta!;
371
    if (offset != 0.0) {
372 373
      _lastNonStationaryTimestamp = details.sourceTimeStamp;
    }
374 375 376
    // By default, iOS platforms carries momentum and has a start threshold
    // (configured in [BouncingScrollPhysics]). The 2 operations below are
    // no-ops on Android.
377
    _maybeLoseMomentum(offset, details.sourceTimeStamp);
378 379
    offset = _adjustForScrollStartThreshold(offset, details.sourceTimeStamp);
    if (offset == 0.0) {
380 381
      return;
    }
382
    if (_reversed) {
383
      offset = -offset;
384
    }
385 386 387 388 389 390 391 392 393
    delegate.applyUserOffset(offset);
  }

  @override
  void end(DragEndDetails details) {
    assert(details.primaryVelocity != null);
    // We negate the velocity here because if the touch is moving downwards,
    // the scroll has to move upwards. It's the same reason that update()
    // above negates the delta before applying it to the scroll offset.
394
    double velocity = -details.primaryVelocity!;
395
    if (_reversed) {
396
      velocity = -velocity;
397
    }
398 399
    _lastDetails = details;

400 401 402 403 404 405 406
    if (_retainMomentum) {
      // Build momentum only if dragging in the same direction.
      final bool isFlingingInSameDirection = velocity.sign == carriedVelocity!.sign;
      // Build momentum only if the velocity of the last drag was not
      // substantially lower than the carried momentum.
      final bool isVelocityNotSubstantiallyLessThanCarriedMomentum =
        velocity.abs() > carriedVelocity!.abs() * momentumRetainVelocityThresholdFactor;
407
      if (isFlingingInSameDirection && isVelocityNotSubstantiallyLessThanCarriedMomentum) {
408 409 410
        velocity += carriedVelocity!;
      }
    }
411
    delegate.goBallistic(velocity);
412 413 414 415 416 417 418
  }

  @override
  void cancel() {
    delegate.goBallistic(0.0);
  }

419
  /// Called by the delegate when it is no longer sending events to this object.
420
  @mustCallSuper
421 422
  void dispose() {
    _lastDetails = null;
423
    onDragCanceled?.call();
424 425
  }

426 427
  /// The type of input device driving the drag.
  final PointerDeviceKind? _kind;
428 429
  /// The most recently observed [DragStartDetails], [DragUpdateDetails], or
  /// [DragEndDetails] object.
430
  dynamic get lastDetails => _lastDetails;
431
  dynamic _lastDetails;
432 433

  @override
434
  String toString() => describeIdentity(this);
435 436
}

nt4f04uNd's avatar
nt4f04uNd committed
437
/// The activity a scroll view performs when the user drags their finger
438 439 440 441 442 443
/// across the screen.
///
/// See also:
///
///  * [ScrollDragController], which listens to the [Drag] and actually scrolls
///    the scroll view.
444
class DragScrollActivity extends ScrollActivity {
445 446
  /// Creates an activity for when the user drags their finger across the
  /// screen.
447
  DragScrollActivity(
448
    super.delegate,
449
    ScrollDragController controller,
450
  ) : _controller = controller;
451

452
  ScrollDragController? _controller;
453

454
  @override
455 456
  void dispatchScrollStartNotification(ScrollMetrics metrics, BuildContext? context) {
    final dynamic lastDetails = _controller!.lastDetails;
457
    assert(lastDetails is DragStartDetails);
458
    ScrollStartNotification(metrics: metrics, context: context, dragDetails: lastDetails as DragStartDetails).dispatch(context);
459 460 461 462
  }

  @override
  void dispatchScrollUpdateNotification(ScrollMetrics metrics, BuildContext context, double scrollDelta) {
463
    final dynamic lastDetails = _controller!.lastDetails;
464
    assert(lastDetails is DragUpdateDetails);
465
    ScrollUpdateNotification(metrics: metrics, context: context, scrollDelta: scrollDelta, dragDetails: lastDetails as DragUpdateDetails).dispatch(context);
466 467 468 469
  }

  @override
  void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) {
470
    final dynamic lastDetails = _controller!.lastDetails;
471
    assert(lastDetails is DragUpdateDetails);
472
    OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, dragDetails: lastDetails as DragUpdateDetails).dispatch(context);
473 474 475 476 477
  }

  @override
  void dispatchScrollEndNotification(ScrollMetrics metrics, BuildContext context) {
    // We might not have DragEndDetails yet if we're being called from beginActivity.
478
    final dynamic lastDetails = _controller!.lastDetails;
479
    ScrollEndNotification(
480 481
      metrics: metrics,
      context: context,
482
      dragDetails: lastDetails is DragEndDetails ? lastDetails : null,
483 484 485 486
    ).dispatch(context);
  }

  @override
487
  bool get shouldIgnorePointer => _controller?._kind != PointerDeviceKind.trackpad;
488 489 490

  @override
  bool get isScrolling => true;
491

492 493 494 495 496
  // DragScrollActivity is not independently changing velocity yet
  // until the drag is ended.
  @override
  double get velocity => 0.0;

497 498 499 500 501
  @override
  void dispose() {
    _controller = null;
    super.dispose();
  }
502 503 504

  @override
  String toString() {
505
    return '${describeIdentity(this)}($_controller)';
506
  }
507 508
}

509
/// An activity that animates a scroll view based on a physics [Simulation].
510 511 512 513 514 515
///
/// A [BallisticScrollActivity] is typically used when the user lifts their
/// finger off the screen to continue the scrolling gesture with the current velocity.
///
/// [BallisticScrollActivity] is also used to restore a scroll view to a valid
/// scroll offset when the geometry of the scroll view changes. In these
Ian Hickson's avatar
Ian Hickson committed
516
/// situations, the [Simulation] typically starts with a zero velocity.
517 518 519 520 521
///
/// See also:
///
///  * [DrivenScrollActivity], which animates a scroll view based on a set of
///    animation parameters.
522
class BallisticScrollActivity extends ScrollActivity {
523 524
  /// Creates an activity that animates a scroll view based on a [simulation].
  ///
525
  /// The [delegate], [simulation], and [vsync] arguments must not be null.
526
  BallisticScrollActivity(
527
    super.delegate,
528 529
    Simulation simulation,
    TickerProvider vsync,
530 531
    this.shouldIgnorePointer,
  ) {
532
    _controller = AnimationController.unbounded(
533
      debugLabel: kDebugMode ? objectRuntimeType(this, 'BallisticScrollActivity') : null,
534 535 536 537 538 539 540
      vsync: vsync,
    )
      ..addListener(_tick)
      ..animateWith(simulation)
       .whenComplete(_end); // won't trigger if we dispose _controller first
  }

541
  late AnimationController _controller;
542 543 544 545 546 547 548 549

  @override
  void resetActivity() {
    delegate.goBallistic(velocity);
  }

  @override
  void applyNewDimensions() {
550
    delegate.goBallistic(velocity);
551 552 553
  }

  void _tick() {
554
    if (!applyMoveTo(_controller.value)) {
555
      delegate.goIdle();
556
    }
557 558 559 560
  }

  /// Move the position to the given location.
  ///
561 562
  /// If the new position was fully applied, returns true. If there was any
  /// overflow, returns false.
563 564 565 566 567
  ///
  /// The default implementation calls [ScrollActivityDelegate.setPixels]
  /// and returns true if the overflow was zero.
  @protected
  bool applyMoveTo(double value) {
568
    return delegate.setPixels(value).abs() < precisionErrorTolerance;
569 570 571
  }

  void _end() {
572
    delegate.goBallistic(0.0);
573 574 575 576
  }

  @override
  void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) {
577
    OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, velocity: velocity).dispatch(context);
578 579 580
  }

  @override
581
  final bool shouldIgnorePointer;
582 583 584 585

  @override
  bool get isScrolling => true;

586 587 588
  @override
  double get velocity => _controller.velocity;

589 590 591 592 593 594 595 596
  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  String toString() {
597
    return '${describeIdentity(this)}($_controller)';
598 599 600
  }
}

601 602 603 604 605 606 607 608 609
/// An activity that animates a scroll view based on animation parameters.
///
/// For example, a [DrivenScrollActivity] is used to implement
/// [ScrollController.animateTo].
///
/// See also:
///
///  * [BallisticScrollActivity], which animates a scroll view based on a
///    physics [Simulation].
610
class DrivenScrollActivity extends ScrollActivity {
611 612 613 614
  /// Creates an activity that animates a scroll view based on animation
  /// parameters.
  ///
  /// All of the parameters must be non-null.
615
  DrivenScrollActivity(
616
    super.delegate, {
617 618 619 620 621
    required double from,
    required double to,
    required Duration duration,
    required Curve curve,
    required TickerProvider vsync,
622
  }) : assert(duration > Duration.zero) {
623
    _completer = Completer<void>();
624
    _controller = AnimationController.unbounded(
625
      value: from,
626
      debugLabel: objectRuntimeType(this, 'DrivenScrollActivity'),
627 628 629 630 631 632 633
      vsync: vsync,
    )
      ..addListener(_tick)
      ..animateTo(to, duration: duration, curve: curve)
       .whenComplete(_end); // won't trigger if we dispose _controller first
  }

634 635
  late final Completer<void> _completer;
  late final AnimationController _controller;
636

637 638 639 640 641
  /// A [Future] that completes when the activity stops.
  ///
  /// For example, this [Future] will complete if the animation reaches the end
  /// or if the user interacts with the scroll view in way that causes the
  /// animation to stop before it reaches the end.
642
  Future<void> get done => _completer.future;
643 644

  void _tick() {
645
    if (delegate.setPixels(_controller.value) != 0.0) {
646
      delegate.goIdle();
647
    }
648 649 650
  }

  void _end() {
651
    delegate.goBallistic(velocity);
652 653 654 655
  }

  @override
  void dispatchOverscrollNotification(ScrollMetrics metrics, BuildContext context, double overscroll) {
656
    OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll, velocity: velocity).dispatch(context);
657 658 659 660 661 662 663 664
  }

  @override
  bool get shouldIgnorePointer => true;

  @override
  bool get isScrolling => true;

665 666 667
  @override
  double get velocity => _controller.velocity;

668 669 670 671 672 673 674 675 676
  @override
  void dispose() {
    _completer.complete();
    _controller.dispose();
    super.dispose();
  }

  @override
  String toString() {
677
    return '${describeIdentity(this)}($_controller)';
678 679
  }
}