I checked that item is removed from both my db and object list but it still remains on the UI.
showDialog(
context: context,
builder: (BuildContext context) {
return Center(
child: SizedBox(
child: AlertDialog(
title: const Text("Edit task"),
content: StatefulBuilder(
builder: (BuildContext context,
void Function(void Function()) setState) {
return Column(
children: [
const Text('Delete your task forever '),
ElevatedButton(
onPressed: () async {
await
DatabaseHelper.instance.delete(int.parse(itemID));
setState(() => Rung.myList = List.from(Rung.myList)..removeAt(int.parse(itemID)));
var element = Rung.myList.elementAt(int.parse(itemID));
dev.log('Removed item exist in current list?: ${Rung.myList.contains(element)}');
},
child: const Icon(
Icons.restore_from_trash_outlined),
),
2
Answers
When you use
removeAt
, you should pass an index of the item of the list instead of itemID.You can try and some changes in your code :