startAutoPlay method
void
startAutoPlay()
Implementation
void startAutoPlay() {
if (!widget.autoScroll) return;
if (itemCount <= 1) return;
//参考RestartableTimer的写法
if (_autoPlayTimer == null && cycleRolling) {
SchedulerBinding.instance!.addPostFrameCallback((timeStamp) {
_autoPlayTimer = Timer.periodic(
Duration(seconds: widget.autoPlaySeconds),
(timer) {
/// 只有一个像素时,不开启自动轮播
if (itemCount <= 1) {
return;
}
/// 用户在触摸时,不开启轮播
if (_inTouch) {
return;
}
/// 非活跃态,不开启自动轮播
if (!_isActive) {
return;
}
// false 说明没有手动滑动过,触发自动滚动
if (!_jumpAutoScroll) {
autoMoveToNextIndex();
} else {
_jumpAutoScroll = false;
}
});
});
}
}