I want to color select value from a ListView like this :
The problem is I print all when I try it , code :
class _ProcedureList extends State<ProcedureList> {
bool isSelected = true;
_isSelected() {
setState(() {
if (isSelected) {
isSelected = false;
} else {
isSelected = true;
}
});
}
@override
Widget build(BuildContext context) {
var procedureList = widget.filteredkits
.where((kit) => kit.brand == widget.brand)
.map((kit) => kit.procedure)
.toSet()
.toList();
return Expanded(
flex: 2,
child: Container(
padding: EdgeInsets.only(left: 35.0),
child: new ListView.builder(
itemCount: procedureList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.all(6.0),
child: Column(
children: <Widget>[
new Container(
width: 300.0,
height: 30.0,
color: Colors.grey[700],
padding: EdgeInsets.all(6.0),
child: new Text(widget.brand),
),
GestureDetector(
onTap: () => widget.getProcedureSelectedandList(procedureList[index].toString()) & _isSelected(),
child: Container(
width: 300.0,
padding: EdgeInsets.all(3.0),
color: !isSelected ? Colors.white : Colors.orange,
child:
new Text(procedureList[index])
),
),
],
),
);
},
),
),
);
}
}
And this is what I achieve , all colored :
I don't know how to only color one item when the event happens and if we can change the text color with the same event better .


