0

我想使用 GestureDetector() onLongPress 选择 GridView 项目我想在现有的 GridView 项目上显示/显示另一个层/容器。我尝试使用 GestureDectector() 中的 bool 变量将布尔变量设置为 True 。但问题是,我在任何 GridView 项目上的 onLongPressed 上选择了所有 GridView 项目。

        GridView.builder(

                  shrinkWrap: false,
                  scrollDirection: Axis.vertical,
                  gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
                   
                      crossAxisCount: 2),
                  itemCount: budgetList.length,
                  itemBuilder: (BuildContext context, int index) {

                    int xNumber= int.parse(bList[index].xNumber);
                    print('Icon Number is here $xNumber');
                    return GestureDetector(
                      onLongPress: (){
                        print('On Long Pressed Detected');
                        setState(() {
                          pressed=true;


                        });
                      },
                      child: Column(
                        children: [
                          IntrinsicHeight(
                            child: (pressed==false)?Row(
                              mainAxisAlignment: MainAxisAlignment.spaceAround,

                              children: <Widget>[
                                Container(
                                  margin: EdgeInsets.only(left: 20.0,top: 15.0,bottom: 15.0),
                                  child: Column(
                                    children: <Widget>[
                                      Icon(xList[xNumber],size: 35.0,color: Color(0xffE44663),),
                                      SizedBox(height: 10.0,),
                                      Text('${bList[index].categoryName}',style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 16.0,
                                          fontWeight: FontWeight.w600,
                                          fontFamily: 'Rajdhani'),)
                                    ],
                                  ),
                                ),
                                Container(
                                  margin: EdgeInsets.only(left: 20.0,top: 15.0,bottom: 15.0),
                                  child: Column(
                                    children: <Widget>[
                                      Text("${bList[index].spentB}",style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 25.0,
                                          fontWeight: FontWeight.bold,
                                          fontFamily: 'Rajdhani'),),
                                      SizedBox(height: 10.0,),
                                      Text('${budgetList[index].totalBudget}',style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 15.0,
                                          fontWeight: FontWeight.w900,
                                          fontFamily: 'Rajdhani'),)
                                    ],

                                  ),
                                ),

                                VerticalDivider(width: 0.7,color: Colors.white60,indent: 0.0,),

                              ],

                            ):Container(
                              color:Color(0xffE44663) ,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,

                                children: <Widget>[
                                  IconButton(icon: Icon(Icons.edit,size: 32.0,color: Colors.white,), onPressed: (){
                                    editCategory(bList[index].id);
                                  }),
                                  IconButton(icon: Icon(Icons.delete,size: 32.0,color: Colors.white,), onPressed: (){
                                    deleteBudget(bList[index].id);
                                  }),
                                ],
                              ),
                            ),
                          ),

                          Divider(height: 0.7,color: Colors.white60,indent: 0.0,)
                        ],
                      ),
                    );

                  }),
4

1 回答 1

1

尝试在有状态的小部件中分离网格项目并移动您在该小部件中提到的布尔值的逻辑......

于 2020-08-23T03:56:26.933 回答