Flutter/Dart 如何在 QuerySnapshot 的一个字段中有两个 e 两个 isGreaterThanOrEqualTo?
Flutter/Dart How can I have two e two isGreaterThanOrEqualTo in one field in a QuerySnapshot?
我想从 firestore 的集合中仅 Futerbuilder 中的这些文件具有相同的 data.But 它不起作用。显然是因为我用了两个 isGreaterThanOrEqualTo.
如何在一个字段中使用两个 isGreaterThanOrEqualTo?
Future getData() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection(tag).where('ckey', isGreaterThanOrEqualTo: 1).where('dkey', isGreaterThanOrEqualTo: 1).getDocuments();
return qn.documents;
}
...
void initState() {
super.initState();
_data = getPosts();
}
...
FutureBuilder(
future: _data
builder: (context, projectSnap)
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)
NoSuchMethodError: The getter 'length' was called on null
你有 NoSuchMethodError: The getter 'length' was called on null
,因为 FutureBuilder
的快照数据在未来解决之前将为空。
您可以提供 initialData
:
FutureBuilder(
future: _data,
initialData: [],
builder: (context, projectSnap) {
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)
或检查构建器中是否存在数据:
FutureBuilder(
future: _data,
builder: (context, projectSnap) {
if (!projectSnap.hasData) return Container();
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)
我想从 firestore 的集合中仅 Futerbuilder 中的这些文件具有相同的 data.But 它不起作用。显然是因为我用了两个 isGreaterThanOrEqualTo.
如何在一个字段中使用两个 isGreaterThanOrEqualTo?
Future getData() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection(tag).where('ckey', isGreaterThanOrEqualTo: 1).where('dkey', isGreaterThanOrEqualTo: 1).getDocuments();
return qn.documents;
}
...
void initState() {
super.initState();
_data = getPosts();
}
...
FutureBuilder(
future: _data
builder: (context, projectSnap)
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)
NoSuchMethodError: The getter 'length' was called on null
你有 NoSuchMethodError: The getter 'length' was called on null
,因为 FutureBuilder
的快照数据在未来解决之前将为空。
您可以提供 initialData
:
FutureBuilder(
future: _data,
initialData: [],
builder: (context, projectSnap) {
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)
或检查构建器中是否存在数据:
FutureBuilder(
future: _data,
builder: (context, projectSnap) {
if (!projectSnap.hasData) return Container();
...
return ListView.builder(
itemCount: projectSnap.data.length,
itemBuilder: (context, index)