setTimer method

void setTimer()

Implementation

void setTimer() {
  if (widget.autoPlay) {
    _timer = Timer.periodic(
      widget.autoPlayDuration,
      (Timer timer) {
        if (widget.state == HomeState.finish &&
            widget.announcements.length > 1 &&
            pageController!.hasClients) {
          setState(() {
            _currentNewsIndex++;
            if (_currentNewsIndex >= widget.announcements.length) {
              _currentNewsIndex = 0;
            }
            pageController?.animateToPage(
              _currentNewsIndex,
              duration: const Duration(milliseconds: 500),
              curve: Curves.easeOutQuint,
            );
          });
        }
      },
    );
  }
}