我想要使用GestureDetector()选择GridView项我想显示/显示现有GridView项上的另一个层/容器我尝试使用GestureDectector()中的布尔变量将布尔变量设置为True。但问题是,我在onLongPressed上的任何GridView项上选择了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,)
],
),
);
}),
发布于 2020-08-23 03:56:27
尝试分离有状态小部件中的网格项,并移动小部件中提到的布尔值的逻辑……
https://stackoverflow.com/questions/63543023
复制