Periodic stream not sending data Periodic stream not sending data dart dart

Periodic stream not sending data


If you check the documentation of the Stream.periodic , you will find this :

Creates a stream that repeatedly emits events at [period] intervals.

So , if you are using 360 seconds as interval, you will have to wait 360 seconds in every change.

Change the timeLeft to one (to emit values every second), change your logic and it should work.

Stream.periodic(    Duration(seconds: 1),


In order to make a timer that stops at a certain time I ended up having to use RxDart and Observables. Here is my solution that creates a stream which emits a value every 1 seconds and stops after a given length of time.

_countdown = Observable.repeat((count) {    var value = '${hours}h : ${minutes}m : ${seconds}s';    if (--seconds < 0) {      seconds = 59;      --minutes;    }    if (minutes < 0) {      if (hours > 0) {        minutes = 59;        --hours;      } else {        minutes = 0;      }    }    if (count == 0)      return Observable.just(value);    else      return Observable.timer(value, Duration(seconds: 1));}, timeLeft + 2);