颤动流组不接受多流

时间:2019-08-15 14:39:51

标签: flutter

我有这样的streambuilder

Widget build(BuildContext context) {
    super.build(context);
var blocData = WeatherBlocProvider.of(context).bloc;
  blocData.setnAnW();
 return StreamBuilder(
          stream: blocData.nAWStream,
          builder: (context, snapshot) {
            print(snapshot.data);
            if (snapshot.hasData) {
                    .......
    }else{
   }

}

在bloc文件中我有流

StreamController nAir = StreamController();
  StreamController nWeather = StreamController()
 nAWStream =
        StreamGroup.merge([nAir.stream, nWeather.stream]).asBroadcastStream();

并且setnAnW()

  setnAnW() {
    setnAir();
    setnWeather();
  }

setnAir()


 setnAir(){  
if(condition){
  //--->in this code they return new data
  nAir.add(Map Type value)
}else{
  //------->in this code i don't need to new data
  //so  i add String type value to recognize difference
  nAir.add(String type value)
}

}

和setnWeather()相同

 setnWeather(){
if(condition){
  //--->in this code they return new data
  nAir.add(List Type value)
}else{
  //------->in this code i don't need to new data
  //so  i add String type value to recognize difference
  nAir.add(double type value)
}

}

当条件为true时,如果我需要向新数据流组发送这两个数据,但在其他情况下(条件为false),则当他们发送String,double类型和刷新时,我认为值也将被返回,但仅返回一个类型值每次都会出现(在我的情况下,只有双类型值)为什么流组不会同时发送两个流?

0 个答案:

没有答案