skip to Main Content

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


  1. When you use removeAt, you should pass an index of the item of the list instead of itemID.

    Login or Signup to reply.
  2. You can try and some changes in your code :

    setState(() => Rung.myList = List.from(Rung.myList)..removeAt(int.parse(itemID)));
    

    To

    setState(() {
      Rung.myList.removeAt(int.parse(itemID));
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search