繁体   English   中英

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

[英]How do I Group and List data according to date using Flutter, Firebase - Firestore Database?

我需要一份按可用日期分组的酒店列表(分组依据 - 添加日期)。 请让我知道可以做什么。 以下是我的代码。 提前致谢。

                                    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: [

我想在每个分组列表上方指定日期

//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,
                                                                ),
                                                              ),
                                                            ),
                                                         
                                                        
                                                          ],
                                                        ),
                          
                                          ],   ),   ), ],);});   },     ),                              
                                      
                                    

这已经在这里得到回答: Flutter/Dart how to groupBy list of maps

package集合通过function实现分组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM