TrainHoppingAnimation constructor

TrainHoppingAnimation(
  1. Animation<double> _currentTrain,
  2. Animation<double>? _nextTrain,
  3. {VoidCallback? onSwitchedTrain}
)

Creates a train-hopping animation.

The current train argument must not be null but the next train argument can be null. If the next train is null, then this object will just proxy the first animation and never hop.

Implementation

TrainHoppingAnimation(
  Animation<double> this._currentTrain,
  this._nextTrain, {
  this.onSwitchedTrain,
}) {
  if (_nextTrain != null) {
    if (_currentTrain!.value == _nextTrain!.value) {
      _currentTrain = _nextTrain;
      _nextTrain = null;
    } else if (_currentTrain!.value > _nextTrain!.value) {
      _mode = _TrainHoppingMode.maximize;
    } else {
      assert(_currentTrain!.value < _nextTrain!.value);
      _mode = _TrainHoppingMode.minimize;
    }
  }
  _currentTrain!.addStatusListener(_statusChangeHandler);
  _currentTrain!.addListener(_valueChangeHandler);
  _nextTrain?.addListener(_valueChangeHandler);
  assert(_mode != null || _nextTrain == null);
}