Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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
Database 使用计时器从firebase数据库检索数据_Database_Firebase_Flutter_Timer - Fatal编程技术网

Database 使用计时器从firebase数据库检索数据

Database 使用计时器从firebase数据库检索数据,database,firebase,flutter,timer,Database,Firebase,Flutter,Timer,如何在Flatter应用程序中使用计时器功能从firebase数据库检索数据 另外,5分钟后将从firebase数据库检索用户请求数据 多谢各位 Future.delayed(Duration(minutes: 5), () { Timer.periodic(Duration(minutes: 5), (Timer t) { setState(() {}); }); }); 好的,把它放到有状态的小部件中,你可以StreamBuilder这

如何在Flatter应用程序中使用计时器功能从firebase数据库检索数据

另外,5分钟后将从firebase数据库检索用户请求数据

多谢各位

  Future.delayed(Duration(minutes: 5), () {
      Timer.periodic(Duration(minutes: 5), (Timer t) {
        setState(() {});
      });
    });

好的,把它放到有状态的小部件中,你可以
StreamBuilder
这在我的模拟器上运行。让我知道它是否适合你


好的,把它放到有状态的小部件中,你可以
StreamBuilder
这在我的模拟器上运行。让我知道它是否适用于您。

我的代码如下所示,但与您的代码不兼容。@wcs424

body: StreamBuilder(
        stream: qs.collection('collection').snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            const Text('Loading');
            return Center(
              child: CircularProgressIndicator(),
            );
          } else {
            return ListView.builder(
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, index) {
                  List<DocumentSnapshot> listedQS = snapshot.data.documents;
                  var random = new Random();
                  for (var i = listedQS.length - 1; i > 0; i--) {
                    var n = random.nextInt(i + 1);
                    var temp = listedQS[i];
                    listedQS[i] = listedQS[n];
                    listedQS[n] = temp;
                  }

                  DocumentSnapshot mypost = listedQS[0];
   snapshot = await Firestore.instance
      .collection('//Collection name')
      .where('index', isGreaterThanOrEqualTo: 0)
      .orderBy('index')
      .limit(1)
      .getDocuments();
正文:StreamBuilder(
流:qs.collection('collection').snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData){
常量文本(“加载”);
返回中心(
子对象:CircularProgressIndicator(),
);
}否则{
返回ListView.builder(
itemCount:snapshot.data.documents.length,
itemBuilder:(上下文,索引){
List listedQS=snapshot.data.documents;
var random=新的random();
对于(var i=listedQS.length-1;i>0;i--){
var n=随机的nextInt(i+1);
var temp=列出的数量[i];
listedQS[i]=listedQS[n];
列出的qs[n]=温度;
}
DocumentSnapshot mypost=listedQS[0];

我的代码如下所示,但与您的代码不兼容。@wcs424

body: StreamBuilder(
        stream: qs.collection('collection').snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            const Text('Loading');
            return Center(
              child: CircularProgressIndicator(),
            );
          } else {
            return ListView.builder(
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, index) {
                  List<DocumentSnapshot> listedQS = snapshot.data.documents;
                  var random = new Random();
                  for (var i = listedQS.length - 1; i > 0; i--) {
                    var n = random.nextInt(i + 1);
                    var temp = listedQS[i];
                    listedQS[i] = listedQS[n];
                    listedQS[n] = temp;
                  }

                  DocumentSnapshot mypost = listedQS[0];
   snapshot = await Firestore.instance
      .collection('//Collection name')
      .where('index', isGreaterThanOrEqualTo: 0)
      .orderBy('index')
      .limit(1)
      .getDocuments();
正文:StreamBuilder(
流:qs.collection('collection').snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData){
常量文本(“加载”);
返回中心(
子对象:CircularProgressIndicator(),
);
}否则{
返回ListView.builder(
itemCount:snapshot.data.documents.length,
itemBuilder:(上下文,索引){
List listedQS=snapshot.data.documents;
var random=新的random();
对于(var i=listedQS.length-1;i>0;i--){
var n=随机的nextInt(i+1);
var temp=列出的数量[i];
listedQS[i]=listedQS[n];
列出的qs[n]=温度;
}
DocumentSnapshot mypost=listedQS[0];
未来加法器(Brew newBrew)异步{
//要保存的值存储在newBrew中并传入
映射入口数据={
“名称”:newBrew.name,
“力量”:newBrew.strength,
“糖”:新鲜的糖,
“索引”:newBrew.index,
};
等待Firestore.instance.collection('//collection name').add(entryData);
}
未来getEntries(Brew newBrew)异步{
QuerySnapshot快照=等待Firestore.instance
.collection(“//集合名称”)
.where('index',大于或等于:Random().nextInt('//此数字应大于文档数))
.orderBy('索引')
.限额(1)
.getDocuments();
if(snapshot.documents.isNotEmpty){
Map documentData=快照。文档[0]。数据;
返酿(
强度:documentData['strngth'],
sugars:documentData['sugars'],
名称:documentData['name'],
索引:documentData['index'],
);
}否则{
snapshot=wait Firestore.instance
.collection(“//集合名称”)
其中('index',大于或等于0)
.orderBy('索引')
.限额(1)
.getDocuments();
Map documentData=快照。文档[0]。数据;
返酿(
强度:documentData['strngth'],
sugars:documentData['sugars'],
名称:documentData['name'],
索引:documentData['index'],
);
}
}
类啤酒{
最后的字符串名;
最后一串糖;
最终强度;
最终整数指数;
酿制({
这个名字,
这个,糖,
这就是力量,
这个索引,,
});
}
您将为每个调用的索引创建和字段,该索引将从0开始,数据库中的每个条目的增量为1。

Future addEntry(Brew newBrew)async{
//要保存的值存储在newBrew中并传入
映射入口数据={
“名称”:newBrew.name,
“力量”:newBrew.strength,
“糖”:新鲜的糖,
“索引”:newBrew.index,
};
等待Firestore.instance.collection('//collection name').add(entryData);
}
未来getEntries(Brew newBrew)异步{
QuerySnapshot快照=等待Firestore.instance
.collection(“//集合名称”)
.where('index',大于或等于:Random().nextInt('//此数字应大于文档数))
.orderBy('索引')
.限额(1)
.getDocuments();
if(snapshot.documents.isNotEmpty){
Map documentData=快照。文档[0]。数据;
返酿(
强度:documentData['strngth'],
sugars:documentData['sugars'],
名称:documentData['name'],
索引:documentData['index'],
);
}否则{
snapshot=wait Firestore.instance
.collection(“//集合名称”)
其中('index',大于或等于0)
.orderBy('索引')
.限额(1)
.getDocuments();
Map documentData=快照。文档[0]。数据;
返酿(
强度:documentData['strngth'],
sugars:documentData['sugars'],
名称:documentData['name'],
索引:documentData['index'],
);
}
}
类啤酒{
最后的字符串名;
最后一串糖;
最终强度;
最终整数指数;
酿制({
这个名字,
这个,糖,
这就是力量,
这个索引,,
});
}
您将为每个被调用的索引创建和字段,该索引从0开始,数据库中的每个条目的增量为1。

我的代码是li
@override
  Widget build(BuildContext context) {
    return Scaffold(
        body: StreamBuilder(
            stream: Firestore.instance.collection('fortunepool').where('index', isGreaterThanOrEqualTo: 0).orderBy('index').limit(1).snapshots(),
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return Container(child: CircularProgressIndicator());
              } else {
                return ListView.builder(
                    itemCount: snapshot.data.documents.length,
                    itemBuilder: (context, index) {
                      List<DocumentSnapshot> listedQS =
                          snapshot.data.documents; //listed documents
                      var random = new Random(); //dart math
                      for (var i = listedQS.length - 1; i > 0; i--) {
                        var n = random.nextInt(i + 1);
                        var temp = listedQS[i];
                        listedQS[i] = listedQS[n];
                        listedQS[n] = temp;
                      }
                      DocumentSnapshot mypost = listedQS[0];
                      return Stack(
Widget build(BuildContext context) {
return Scaffold(
    body: StreamBuilder(
        stream: Firestore.instance
            .collection('fortunepool')
            .where('index', isGreaterThanOrEqualTo: 0)
            .orderBy('index')
            .limit(1)
            .snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Container(child: CircularProgressIndicator());
          } else {
            return ListView.builder(
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, index) {
                  List<DocumentSnapshot> listedQS =
                      snapshot.data.documents; //listed documents

                  DocumentSnapshot mypost = listedQS[0];
                  return Stack(