简体   繁体   English

如何使用 Flutter、Firebase - Firestore 数据库根据日期对数据进行分组和列出?

[英]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.

相关问题 如何使用 excel 或 google 电子表格或 CSV 使用 excel 导入 firebase firestore 数据库中的批量数据 - How to import bulk data in firebase firestore database from excel or google spreadsheet or CSV using flutter 使用 Flutter Firebase Firestore 从数据库获取地理点数据 - Getting Geopoint Data from Database Using Flutter Firebase Firestore 我可以使用 jQuery 将数据导入 Firebase Firestore 数据库吗? - Can I import data to Firebase Firestore database using jQuery? 我无法使用 firebase firestore 将数据存储到数据库 - I can't store data to database using firebase firestore 如何在 Firebase Firestore 中查询 Flutter 中 Geopoint 类型的字段? - How do I Query Firebase Firestore for a field of type Geopoint in Flutter? 如何使用 flutter 中的 JSONserializable 在 Cloud Firestore 数据库中设置嵌套字段 - How do I set up a nested field in a Cloud Firestore database using JSONserializable in flutter 在 Flutter 中,如果我们在 firestore 中有日期参数,我们如何使用 firebase 获取特定日期范围之间的数据? - In Flutter how can we able to get the data between specific date ranges using firebase if we had date parameter in firestore? 使用 flutter 从 firebase Firestore 获取数据 - fetching data from firebase firestore using flutter 如何使用 NextJs API、Firebase Firestore、axios 和 TypeScript 从 Firebase 集合中获取数据? - How do I get data from Firebase collection using NextJs API, Firebase Firestore, axios and TypeScript? 如何将数据从我的数据库 (Firebase Firestore) 发送到我的 React Native 应用程序? - How do I send data from my database (Firebase Firestore) to my React Native app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM