0

Hey i'm trying to add a reorderable list view to a list but, i'm getting an issue and i don't know why.

error: package:flutter/src/widgets/framework.dart': Failed assertion: line 5403 pos 14: '_dependents.isEmpty': is not true.

My list is called toDoList and its in a database for saving on your device. database is db

Here is the Reorderable List View part of my code.

 body: ReorderableListView.builder(
    itemCount: db.toDoList.length,
    //this code is uesd to reorder the list
    onReorder: (oldIndex, newIndex) => setState(() {
      final index = newIndex;

      final item = db.toDoList.removeAt(index);
      db.toDoList.insert(index, item);
    }),
    itemBuilder: (context, index) {
      //code is needed to define each item on list as item
      final item = db.toDoList[index];

      return toDoTile(
        //key is used to set each item on list as unique
        key: ValueKey(item),
        taskName: db.toDoList[index][0],
        taskCompleted: db.toDoList[index][1],
        onChanged: (value) => checkBoxChanged(value, index),
        deleteFunction: (context) => deleteTask(index),
        editTask: (context) => editTask(index),
      );
    },
  ),
);

}

any idea why i'm having this issue?

menamejaff
  • 39
  • 1
  • 4
  • Does this answer your question? [Failed assertion: line 3927 pos 14: '\_dependents.isEmpty': is not true](https://stackoverflow.com/questions/47198533/failed-assertion-line-3927-pos-14-dependents-isempty-is-not-true) – Ivo Mar 21 '23 at 10:44

1 Answers1

0

You should not removeAt newIndex instead remove at the oldIndex:

onReorder: (oldIndex, newIndex) => setState(() {
      final index = newIndex;

      final item = db.toDoList.removeAt(oldIndex);
      db.toDoList.insert(index, item);
    }),