zoukankan      html  css  js  c++  java
  • stream

    自带的:

    单一

    class DataBloc {
      StreamController dataBloc = StreamController();
      StreamSink get dataSink => dataBloc.sink;
    }
    

      

    addData(){
        dataBloc.dataSink.add('addsfdb');
      }
    

      



    StreamBuilder(
                stream: dataBloc.dataBloc.stream,
                builder: (context, snapshot){
                  if(snapshot.hasData){
                    return Text('${snapshot.data}');
                  }else{
                    return Text('first');
                  }
                },
              ),
    

      

    多次

    class DataBloc {
      StreamController dataBloc;
      DataBloc(){
        dataBloc = StreamController.broadcast();
      }
      Stream get dataStream => dataBloc.stream;
      StreamSink get dataSink => dataBloc.sink;
    }
    

      

    StreamBuilder(
                stream: dataBloc.dataStream,
                builder: (context, snapshot){
                  if(snapshot.hasData){
                    print('this first ${snapshot.data}');
                    return Text('${snapshot.data}');
                  }else{
                    return Text('first');
                  }
                },
              ),
    
              StreamBuilder(
                stream: dataBloc.dataStream,
                builder: (context, snapshot){
                  if(snapshot.hasData){
                    print('this seconds. ${snapshot.data}');
                    return Text('${snapshot.data}');
                  }else{
                    return Text('second');
                  }
                },
              ),
    

      

     addData(){
        dataBloc.dataSink.add('addsfdb');
      }
    

      

    rxdart:

    class DataBloc {
      PublishSubject dataBloc = PublishSubject();
    }
    

      

    StreamBuilder(
                stream: dataBloc.dataBloc.stream,
                builder: (context, snapshot){
                  if(snapshot.hasData){
                    print('this first ${snapshot.data}');
                    return Text('${snapshot.data}');
                  }else{
                    return Text('first');
                  }
                },
              ),
    
              StreamBuilder(
                stream: dataBloc.dataBloc.stream,
                builder: (context, snapshot){
                  if(snapshot.hasData){
                    print('this seconds. ${snapshot.data}');
                    return Text('${snapshot.data}');
                  }else{
                    return Text('second');
                  }
                },
              ),
    

      

    addData(){
        dataBloc.dataBloc.add('xyz');
      }
    

      

  • 相关阅读:
    Python3中urllib使用介绍
    python urllib和urllib3包
    Python--urllib3库
    Python基础-变量作用域
    Python 面向对象三(转载)
    Python 面向对象二(转载)
    Python 面向对象一(转载)
    YAML 在Python中的应用
    Redis 命令二
    基于Redis的Bloomfilter去重(转载)
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10839848.html
Copyright © 2011-2022 走看看