首页 > 解决方案 > 如何在颤动中从云 Firestore 中获取数据的列表的特定索引处进行更改?

问题描述

在我的颤振应用程序中,我从 Firestore 的列表中获取了我的数据,现在想要一个 ADD 或 REMOVE 选项来增加或减少列表中该特定项目的单位数量,但经过几次尝试后无法做到这一点作为计数整个列表上的更新不是该索引中的特定元素。任何人都可以帮助我吗

CustomScrollView(
                physics: BouncingScrollPhysics(),
                slivers: <Widget>[
                  SliverList(
                    delegate: SliverChildBuilderDelegate((context, index){
                      return Container(
                  margin: EdgeInsets.only(top: 15.0,left: 15.0,right: 15.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Container(
                        child: Text(snapshot.data.documents[index].documentID,style: TextStyle(fontFamily: "DelishN", fontSize: 15.0),),
                      ),
                      Container(
                        decoration: BoxDecoration(
                          border: Border.all(
                            width: 2.0,
                            color: Colors.black
                          ),
                          borderRadius: BorderRadius.circular(23.0)
                        ),
                        child: Row(
                          children: <Widget>[
                            FloatingActionButton(
                              onPressed: (){
                                add();
                              },
                              mini: true,
                              child: Icon(Icons.add, color: Colors.black,),
                              backgroundColor: Colors.white,
                            ),
                            SizedBox(
                              width: 7.0,
                            ),
                            Text(_n.toString(), style: TextStyle(fontFamily: 'DelishN',),),
                            SizedBox(
                              width: 7.0,
                            ),
                            FloatingActionButton(
                              onPressed: (){
                                minus();
                              },
                              mini: true,
                              child: Icon(Icons.remove, color: Colors.black,),
                              backgroundColor: Colors.white,)
                          ],
                        ),
                      )
                    ],
                  )
            );
                    },
                    childCount: snapshot.data.documents.length))],
              )

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


推荐阅读