Flutter:如何为列表中显示的项目放置 GestureDetector
Flutter: How to put GestureDetector for items displayed from list
我有一个显示类别列表的应用程序,我想为屏幕上显示的每个类别添加 GestureDetector 以激活所选类别。
我的列表是这样的:List<list> category;
这是我的代码:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: category.length,
itemBuilder: (context,index){
bool isSelected = false;
if (index == 0) {
isSelected = true;
}
return Row(
children: <Widget>[
Column(
children: <Widget>[
Container(
width: 68,
height: 68,
decoration: BoxDecoration(
color: isSelected?
Colors.white:
Colors.transparent,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Colors.white,
width: 1,
),
boxShadow: isSelected
?[
BoxShadow(
color: Color(0x14000000),
blurRadius: 10
)
]: null
),
child: Center(
child: Image.asset(category[index].imageUrl),
),
),
],
),
],
);
},
),
在 Row
上使用 GestureDetector
GestureDetector(
onTap: () {
// Call back of click event
},
child: Row(
),
),
我有一个显示类别列表的应用程序,我想为屏幕上显示的每个类别添加 GestureDetector 以激活所选类别。
我的列表是这样的:List<list> category;
这是我的代码:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: category.length,
itemBuilder: (context,index){
bool isSelected = false;
if (index == 0) {
isSelected = true;
}
return Row(
children: <Widget>[
Column(
children: <Widget>[
Container(
width: 68,
height: 68,
decoration: BoxDecoration(
color: isSelected?
Colors.white:
Colors.transparent,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Colors.white,
width: 1,
),
boxShadow: isSelected
?[
BoxShadow(
color: Color(0x14000000),
blurRadius: 10
)
]: null
),
child: Center(
child: Image.asset(category[index].imageUrl),
),
),
],
),
],
);
},
),
在 Row
GestureDetector
GestureDetector(
onTap: () {
// Call back of click event
},
child: Row(
),
),