[英]How to convert a Future in flutter to a Stream
I have a function that returns a Future of the type duration. 我有一个函数,返回持续时间类型的Future。
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). 未来需要来自timerservice的持续时间,该服务会自我更新以运行计时器。现在,我希望将future转换为流,以便可以在StreamBuilder中显示它(Futurebuilder不会更新计时器)。
Any way to convert the future to a stream of duration will be helpful. 将未来转换为持续时间流的任何方法都将有所帮助。
您可以使用Stream.fromFuture(dur)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.