Reputation: 5
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']),
),
);
},
),
);`
},
),
Upvotes: 0
Views: 800
Reputation: 171
Thats happens because the x
is the same for all cards, you need separate this guy, my suggestion is put the x
inside DocumentSnapshot
, so u can change only tapped card, something like this:
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(() {
myCards['x'] = Text('Tapped');
});
},
leading: myCards['x'],
title: Text(myCards['CardPin']),
trailing: Text(myCards['Value']),
),
);
},
),
);`
},
),
Upvotes: 1
Reputation: 34180
Add key to your card and provide the unique value, in your case it is your index
Card(
key: ValueKey(index),
//....
)
Upvotes: 1