I am working with Flutter and am struggling to remove a Dismissible object from the tree. Below is my code. I have created a custom class that is stored in the list 'newlist.' I seemingly remove the Dismissible object from the List and setState(), but it does not seem to work. Any help is greatly appreciated.
return new Dismissible(key: new Key("newlist"),
direction: DismissDirection.horizontal,
onDismissed: (DismissDirection direction) {
setState(() {
newlist.remove(newlist[index]);
print(newlist.length);
});
},
child: new ListTile(
leading: const
Icon(Icons.album),
title: new Text(newlist[index].amount),
subtitle: new Text(
newlist[index].name)));
})),
I have solved it using items name + lists length as a key. Because there could be some items with the same value
return Dismissible(
key: Key(item.name + _paths.length.toString()),
onDismissed: (direction) {
setState(() {
_paths.removeAt(index);
});
// Show a red background as the item is swiped away
background: Container(color: Colors.red),
child: Container(child: new Texts().tallText(item.name)),
);
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