I have a list of widgets built using a listview builder. Problem is when i change the state of an item in the list(using the ontap property of the list item) the state changes quite alright but an exact replica of that mutated list item is added at the very top of my list
Snippet
List data = [1,2,2,1,1];
return Scrollbar(
child: ListView.builder(
itemCount: data.length,
itemBuilder: (context, int index) {
final s = data[index];
return ListTile(
dense: false,
leading: leading(leading),
title: Text(s),
subtitle: Text(
"${s}",
style: Theme.of(context).textTheme.caption,
),
onTap: () {
setState(() {//do something to the subtitle});
},
);
},
),
);
Try giving everyListTile a unique Key
For example:
return ListTile(
key: Key("${index}"),
dense: false,
leading: leading(leading),
title: Text(s),
subtitle: Text(
"${s}",
style: Theme.of(context).textTheme.caption,
),
onTap: () {
setState(() {//do something to the subtitle});
},
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With