I have a list of containers having like button each. I want to change the color of like button when it clicked. But instead of changing the color of 1 like button when I clicked on like button it is changing the color of all like buttons in all containers. .
Here is my code.
var tap = false;
body: ListView.builder(
itemCount: Get.find<UserController>().jobsList.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.fromLTRB(15, 15, 15, 5),
child: Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 2,
color: Colors.black,
)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Hello World'),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
onTap: () {
setState(() {
tap = !tap;
});
},
child: tap
? Text(
'Like',
style: TextStyle(
fontSize: 16, color: colorGreen),
)
: Text(
'Like',
style: TextStyle(
fontSize: 16, color: Colors.white),
),
),
Text(
'Comment',
style: TextStyle(fontSize: 16, color: Colors.white),
),
Text(
'Share',
style: TextStyle(fontSize: 16, color: Colors.white),
),
],
)
],
),
),
);
}),