Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 把一条小溪变成飘荡的未来_Flutter_Dart_Futuretask - Fatal编程技术网

Flutter 把一条小溪变成飘荡的未来

Flutter 把一条小溪变成飘荡的未来,flutter,dart,futuretask,Flutter,Dart,Futuretask,这里是一个初学者,所以如果我的问题很愚蠢,请不要介意 如何将流转换为未来 我有一个流,它只是多次调用请求的URL,因为它是一个流。我希望能够得到数据,而不是加载状态。。。因为我一直都在装东西 是否有类似于Future.fromStream()函数的东西,而我却错过了它 我能做到这一点吗 我没有提供任何代码,因为我认为如果您需要代码,就不需要它,我可以编辑问题流有第一个方法,这将返回未来 _profileService.profileStream.firstWhere((element) =>

这里是一个初学者,所以如果我的问题很愚蠢,请不要介意

如何将流转换为未来

我有一个流,它只是多次调用请求的URL,因为它是一个流。我希望能够得到数据,而不是加载状态。。。因为我一直都在装东西

是否有类似于
Future.fromStream()
函数的东西,而我却错过了它

我能做到这一点吗


我没有提供任何代码,因为我认为如果您需要代码,就不需要它,我可以编辑问题

第一个
方法,这将返回
未来

_profileService.profileStream.firstWhere((element) => false);

流和未来是两个不同的概念

在您使用时,stream会不断更新数据,而未来只是一次。 使用流的示例:购物车、物品列表 登录后使用future:getUserDetails的示例

如果您使用的是stream,则可以使用streambuilder构建UI

StreamBuilder<User>(
  stream: userBloc.author, // your stream here
  builder:
      (BuildContext context, AsyncSnapshot<User> snapshot) {
    if (snapshot.connectionState == ConnectionState.active && snapshot.hasData) {
      // do your work here
    } else {
      return CircularprogressIndicator();
    }
  },
)
StreamBuilder(
stream:userBloc.author,//此处是您的流
建设者:
(BuildContext上下文,异步快照){
if(snapshot.connectionState==connectionState.active&&snapshot.hasData){
//你在这里工作吗
}否则{
返回循环ProgressIndicator();
}
},
)