【发布时间】:2020-07-26 12:17:19
【问题描述】:
我正在学习 Flutter/Dart 并尝试连接到我的 Firestore 数据库。我想查询文档的集合,然后查询该文档中的集合。我还在学习 Dart,但我发现异步流构建应该是最好的方法。
我试过db.instance.collect('').document('').collection('').snapshot(),但streambuilder似乎不支持这个,我得到了错误
没有为类型“查询”定义方法“集合”。
我必须在db.instance.collection('').where('name' isEqualto: 'Name').snapshots()之后结束我的查询
下面是一个例子。
我的目标是查询所有类并将它们显示在一个列表中。
示例 -
教师 教师姓名
类 Class1 Class2
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class ClassListPage extends StatelessWidget{
@override
Widget build(BuildContext context){
return Material(
child: new StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('Teachers').
where('name', isEqualTo: 'Dr. Who')
//.collection('Classes') <--This is not working
.snapshots(),
//HERE is where I want to query for the 'classes' collection then query
//for the documents within
builder:(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if(!snapshot.hasData)return new Text('..Loading');
return new ListView(
children: snapshot.data.documents.map((document){
return new ListTile(
title: new ListTile(
title: new Text(document['name']),
),
);
}).toList(),
);
}
),
);
}
}
【问题讨论】:
标签: flutter dart google-cloud-firestore nosql