TickerFuture _animateToInternal(float target, TimeSpan?duration = null, Curve curve = null) { curve = curve ?? Curves.linear; TimeSpan?simulationDuration = duration; if (simulationDuration == null) { D.assert(() => { if ((this.duration == null && _direction == _AnimationDirection.reverse && reverseDuration == null) || (this.duration == null && _direction == _AnimationDirection.forward)) { throw new UIWidgetsError( "AnimationController.animateTo() called with no explicit Duration and no default duration or reverseDuration.\n" + "Either the \"duration\" argument to the animateTo() method should be provided, or the " + "\"duration\" and/or \"reverseDuration\" property should be set, either in the constructor or later, before " + "calling the animateTo() function." ); } return(true); }); float range = upperBound - lowerBound; float remainingFraction = range.isFinite() ? (target - _value).abs() / range : 1.0f; TimeSpan directionDuration = (_direction == _AnimationDirection.reverse && reverseDuration != null) ? reverseDuration.Value : this.duration.Value; simulationDuration = TimeSpan.FromTicks((long)(directionDuration.Ticks * remainingFraction)); } else if (target == value) { simulationDuration = TimeSpan.Zero; } stop(); if (simulationDuration == TimeSpan.Zero) { if (_value != target) { _value = target.clamp(lowerBound, upperBound); notifyListeners(); } _status = (_direction == _AnimationDirection.forward) ? AnimationStatus.completed : AnimationStatus.dismissed; _checkStatusChanged(); return(TickerFuture.complete()); } D.assert(simulationDuration > TimeSpan.Zero); D.assert(!isAnimating); return(_startSimulation( new _InterpolationSimulation(_value, target, simulationDuration.Value, curve))); }
void _animate() { if (_animationController.isAnimating) { return; } bool wasHeldDown = _buttonHeldDown; TickerFuture ticker = _buttonHeldDown ? _animationController.animateTo(1.0f, duration: kFadeOutDuration) : _animationController.animateTo(0.0f, duration: kFadeInDuration); ticker.then(_ => { if (mounted && wasHeldDown != _buttonHeldDown) { _animate(); } }); }