I am trying to display a list tile in flutter based on list of data from cloud firestore. I want the leading icon to change for each tile when the tile is tapped. My problem is whenever I tap any tile, the whole list changes. I want only the tapped tile to change. Here is my code:
StreamBuilder(
stream: Firestore.instance
.collection('Recharge_Card')
.snapshots(),
//print an integer every 2secs, 10 times
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("Loading..");
}
return SizedBox(
height: _height / 1.9,
child: ListView.builder(
// itemExtent: 80.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot myCards =
snapshot.data.documents[index];
return Card(
elevation: 20.0,
child: ListTile(
onTap: () {
setState(() {
x = Text('Tapped');
});
},
leading: x,
title: Text(myCards['CardPin']),
trailing: Text(myCards['Value']),
),
);
},
),
);`
},
),