[英]How do I Group and List data according to date using Flutter, Firebase - Firestore Database?
I need to have a list of hotels grouped by the dates available (group by - the date they have been added).我需要一份按可用日期分组的酒店列表(分组依据 - 添加日期)。 Please let me know what can be done.
请让我知道可以做什么。 The following is my code.
以下是我的代码。 Thanks in advance.
提前致谢。
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('hotels')
.snapshots(),
builder:
(context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView.builder(
itemCount: snapshot.data?.docs.length,
itemBuilder: (context, index) {
return Stack(
children: [
I want to have the date specified above each grouped list我想在每个分组列表上方指定日期
//the date captured from the group by condition
Text("${example date}", style: TextStyle(
color: Colors.white
),),
Container(
child: Column(
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(
right: 10.0),
child: Text(
"${snapshot.data!.docs[index]['name']
.toString()}",
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
],
),
], ), ), ],);}); }, ),
This has already been answered here: Flutter/Dart how to groupBy list of maps这已经在这里得到回答: Flutter/Dart how to groupBy list of maps
The package collection implements the groupBy function.
package集合通过function实现分组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.