如何将Flutter中的Future转换为Stream [英] How to convert a Future in flutter to a Stream

查看:543
本文介绍了如何将Flutter中的Future转换为Stream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回持续时间类型为Future的函数。

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;}

将来需要一个timerservice持续时间,该服务会更新自身以运行计时器。现在我希望将未来转换为流,以便可以在StreamBuilder中显示它(Futurebuilder不会更新计时器)。

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).

任何转换方式

推荐答案

您可以使用 Stream.fromFuture(dur )

这篇关于如何将Flutter中的Future转换为Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆