如何在FireStore(Firebase数据库)中显示用户列表仅基于经过验证的Fild! 因此,如果有未验证的内容,则不会在streambuilder中列出它们,在这里是我的示例,但出现错误!
Widget verified (){
return FutureBuilder(
future: Firestore.instance.collection('users').where('verified ',isEqualTo: 'true').getDocuments(),
builder: (context, data){
return ListView(
children: <Widget>[
Text('${data.data['verified '].toString()}'),
],
);
},
);
}
错误是:
Class 'QuerySnapshot' has no instance method '[]'.
Receiver: Instance of 'QuerySnapshot'
Tried calling: []("verified ")
答案 0 :(得分:1)
我通常在Firestore中使用流生成器,您可以这样使用:
return StreamBuilder(
stream: Firestore.instance
.collection('users')
.where('verified ', isEqualTo: 'true')
.snapshots(),
builder: (context, data) {
if (data.hasData) {
return ListView(
children: <Widget>[
Text('${data.data['verified '].toString()}'),
],
);
}
return Center(
child: CircularProgressIndicator(),
);
},
);
如果您要使用将来的构建器,则必须检查是否有数据
return FutureBuilder(
future: Firestore.instance
.collection('users')
.where('verified ', isEqualTo: 'true')
.getDocuments(),
builder: (context, data) {
if (data.data != null) { //data.connectionState == ConnectionState.done
return ListView(
children: <Widget>[
Text('${data.data['verified '].toString()}'),
],
);
}
return CircularProgressIndicator();
},
);