流生成器主体中频繁更新文档和调用方法

时间:2019-04-07 13:47:10

标签: firebase dart flutter google-cloud-firestore

我有一个StreamBuilder。在此流生成器的主体中,我放置了一种方法,该方法大约每30秒更新一次文档字段,并且工作正常。我还有一个按钮,按下该按钮会将数据设置到一个文档,然后更新另一个文档,如下图所示

    method_1()async{
    //set data to some collection
    }


    method_2()async{
    // update some other colections document
    }

    //method in body of stream builder
    update_coll()async
    // do update
    {
    }
    streamBuilder(
    Stream:Firestore.instance.collection('some_collection');

    // somewhere in the body of the streamBuilder
    update_coll(); // update every 30 seconds

    // and a button in listviewBuilder
    RaisedButton(
    onPressed(){
    method_1().then((_){
         method_2();
        });
      }
    ),
 );

问题是,当我按下按钮来运行这两种方法时,什么都没有发生(raisedButtton的方法中将数据发送到我的cloudFiresore DB的方法不发送数据),但是当我注释掉{{ 1}}方法有效。我在做什么错了,并且有一种更好的方法来尝试用update_coll();来做特别的事情,update_coll();需要经常更新字段

我在需要时致电setstate

0 个答案:

没有答案