Flutter QuerySnapshot过滤器零-颤振
我正在尝试筛选关于颤振的查询,但它返回空值Flutter QuerySnapshot过滤器零-颤振,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,我正在尝试筛选关于颤振的查询,但它返回空值 Future getChamados() async { final QuerySnapshot result = await Future.value(Firestore.instance .collection("chamados") .where("tid", isEqualTo: tid).orderBy('dateTime') .getDocume
Future getChamados() async {
final QuerySnapshot result = await Future.value(Firestore.instance
.collection("chamados")
.where("tid", isEqualTo: tid).orderBy('dateTime')
.getDocuments());
return result.documents;
}
FutureBuilder
child: FutureBuilder(
future: getChamados(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return new Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.data.length == 0 || tid == null || tid == "") {
return new Center(
child: Text(
'Nenhum Chamado.',
style: TextStyle(color: Colors.grey),
),
);
} else {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Card(
elevation: 8.0,
margin: new EdgeInsets.symmetric(
horizontal: 6.0, vertical: 5.0),
child: Container(
decoration:
BoxDecoration(color: Color(0xFF00aacb)),
child: ListTile(
contentPadding: EdgeInsets.symmetric(
horizontal: 15.0, vertical: 1.0),...
错误
child: FutureBuilder(
future: getChamados(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return new Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.data.length == 0 || tid == null || tid == "") {
return new Center(
child: Text(
'Nenhum Chamado.',
style: TextStyle(color: Colors.grey),
),
);
} else {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Card(
elevation: 8.0,
margin: new EdgeInsets.symmetric(
horizontal: 6.0, vertical: 5.0),
child: Container(
decoration:
BoxDecoration(color: Color(0xFF00aacb)),
child: ListTile(
contentPadding: EdgeInsets.symmetric(
horizontal: 15.0, vertical: 1.0),...
生成FutureBuilder时抛出以下NoSuchMethodError(脏,状态:_FutureBuilderState#2f75d):
对null调用了getter“length”。
收件人:空
尝试呼叫:长度
理想情况下,当ConnectionState为
ConnectionState.done
时,您应该访问快照.data
。当快照
为空时,您正试图访问.legnth
当ConnectionState为ConnectionState.done
时,检查长度并有条件地呈现小部件。否则显示加载小部件。尝试如下重构FutureBuilder
:
FutureBuilder(
future:getChamados(),
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.done&&snapshot.hasData){
返回snapshot.data.length==0 | | tid==null | | tid==
?ListView.builder(…)
:中心(
子:文本(
“Nenhum Chamado”,
样式:TextStyle(颜色:Colors.grey),
),
);
}
返回循环ProgressIndicator();
},
),
Post FutureBuilder的代码。添加了FutureBuilder。我按照您的指示对其进行了更改,您给出了以下错误:侦听查询(其中tid==24082017 order by dateTime,name)失败:状态{code=FAILED\u premission,description=查询需要索引。查找问题。需要在cloud firestore中创建索引。您可以通过错误本身中生成的链接创建索引。