How to change the color of the tapped list item in list view? Is it possible to change the color of the corresponding list item when clicked?
Color color = Colors.red;
ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
setState(() {
color = Colors.blue;
});
},
child: Container(
margin: EdgeInsets.all(15),
padding: EdgeInsets.all(10),
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
border: Border.all(color: Colors.grey[300]),
color: color
),
),
);
},
),
What am i doing wrong here? clicking one container changes all container's color