animateIfNeeded method
void
animateIfNeeded(
- Rect rect
)
Implementation
void animateIfNeeded(Rect rect) {
if (_lastRect != null && _lastRect != rect) {
final bool inAnimation = isAnimating;
Rect from = Rect.fromLTWH(
_lastRect!.left - rect.left,
_lastRect!.top - rect.top,
_lastRect!.width,
_lastRect!.height,
);
if (inAnimation) {
// We need to recompute the from.
final Rect currentRect = _animation!.value!;
from = Rect.fromLTWH(
currentRect.left + _lastRect!.left - rect.left,
currentRect.top + _lastRect!.top - rect.top,
currentRect.width,
currentRect.height,
);
}
_isAnimating = true;
_animation = _controller.drive(CurveTween(curve: curve)).drive(
createRectTween(
from,
Rect.fromLTWH(
0,
0,
rect.width,
rect.height,
),
),
);
if (!inAnimation) {
SchedulerBinding.instance!.addPostFrameCallback((_) {
_controller.forward();
});
} else {
SchedulerBinding.instance!.addPostFrameCallback((_) {
final Duration duration =
_controller.duration! * (1 - _controller.value);
_controller.reset();
_controller.animateTo(
1,
duration: duration,
);
});
}
}
_lastRect = rect;
}