Reputation: 1369
I have an app that displays a list of categories and I want to add GestureDetector for every category shown on the screen to activate the selected one.
My list is like so: List<list> category;
Here is my code:
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),
),
),
],
),
],
);
},
),
Upvotes: 1
Views: 1026
Reputation: 34170
Use GestureDetector
on Row
GestureDetector(
onTap: () {
// Call back of click event
},
child: Row(
),
),
Upvotes: 2