timer in flutter

var duration = 30;


startTimer(){
   Timer.periodic(const Duration(seconds: 1), (timer) {
    if (duration == 0) {
      print('Cancel timer');
      timer.cancel();
    }else{
      setState(() {
        duration --;
      });

    }
  });
}

Add set timer in init state

Sign In or Register to comment.