首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在长按下选择的GridView项目上显示另一个容器

如何在长按下选择的GridView项目上显示另一个容器
EN

Stack Overflow用户
提问于 2020-08-23 11:12:12
回答 1查看 32关注 0票数 0

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

代码语言:javascript
代码运行次数:0
运行
复制
        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,)
                        ],
                      ),
                    );

                  }),
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-23 11:56:27

尝试分离有状态小部件中的网格项,并移动小部件中提到的布尔值的逻辑……

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63543023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档