[英]How to use GroupedListView using Streambuilder and firebase QuerySnapshot
I am trying to use the GroupedListview() showing some data from Firebase cloud.我正在尝试使用 GroupedListview() 显示来自 Firebase 云的一些数据。 When i am using the normal Listview.builder() everything is working fine.
当我使用普通的 Listview.builder() 时,一切正常。 But i dont get the GroupedListview working.
但我没有让 GroupedListview 工作。 My Snapshot.docs has a Timestamp called ['date'] and i want to use it to seperate sort and seperate the List.
我的 Snapshot.docs 有一个名为 ['date'] 的时间戳,我想用它来分隔排序和分隔列表。
here you see my normal ListView:在这里你可以看到我正常的 ListView:
StreamBuilder<QuerySnapshot>(
stream: _firestoreDb,
builder: (context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return ListView.builder(
physics: BouncingScrollPhysics(),
reverse: true,
itemCount: snapshot.data.docs.length,
itemBuilder: (context, int index) {
return JumpTile(
snapshot: snapshot.data,
index: index,
);
});
}),
This is my try to use the GroupedListview:这是我尝试使用 GroupedListview:
StreamBuilder<QuerySnapshot>(
stream: _firestoreDb,
builder: (context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return GroupedListView(
elements: snapshot.data.docs,
groupBy: (element) => element['date'],
groupHeaderBuilder: (element) =>
Text(element['date'].toString()),
indexedItemBuilder: (context, snapshot, int index) {
return JumpTile(
snapshot: snapshot.data,
index: index,
);
});
}),
This is the Error i get shown: type '() => Map<String, dynamic>' is not a subtype of type 'QuerySnapshot'这是我显示的错误:类型'() => Map<String, dynamic>' 不是类型'QuerySnapshot' 的子类型
you can use FutureBuilder and ins你可以使用 FutureBuilder 和 ins
FutureBuilder(
future: _firestoreDb,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
} else {
return Container(
child: GroupedListView<dynamic, String>(
elements: snapshot.data.docs,
groupBy: (element) => element.date, //and edit these lines
groupSeparatorBuilder: (String value) =>
Text(value),itemBuilder: (c, element) {
return ListTile(
title: Text(element.data),
);
}),
);
}
}),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.