ganraj kelkar
ganraj kelkar

Reputation: 335

How to convert a Future in flutter to a Stream

I have a function that returns a Future of the type duration.

Future loadur(TimerService timerservice) async {
 var dur = Duration.zero;
 dur = await timerservice.currentDuration();
 return dur;}

The future takes duration from a timerservice which updates itself to run a timer.Now i want the future to be converted to a stream so i can show it in a StreamBuilder(Futurebuilder doesn't update the timer).

Any way to convert the future to a stream of duration will be helpful.

Upvotes: 19

Views: 21863

Answers (1)

Mohammed Mahmoud
Mohammed Mahmoud

Reputation: 1148

you can Use Stream.fromFuture(dur)

Upvotes: 43

Related Questions