Checklist: Let items be re-ordered

This commit is contained in:
Vishesh Handa
2020-02-10 17:10:54 +01:00
parent dbbe8589c6
commit 1cd0b967de
2 changed files with 29 additions and 5 deletions

View File

@ -82,6 +82,32 @@ class Checklist {
nodes.remove(item.element);
items.remove(item);
}
ChecklistItem removeAt(int index) {
assert(index >= 0 && index <= items.length);
var item = items[index];
assert(nodes.contains(item.element));
nodes.remove(item.element);
items.removeAt(index);
return item;
}
void insertItem(int index, ChecklistItem item) {
if (index == 0) {
items.insert(0, item);
nodes.insert(0, item.element);
return;
}
var prevItem = items[index];
var nodeIndex = nodes.indexOf(prevItem.element);
nodes.insert(nodeIndex + 1, item.element);
items.insert(index, item);
}
}
/// Copied from flutter-markdown - cannot be merged as we added xUpperCase and changed the regexp

View File

@ -73,15 +73,13 @@ class ChecklistEditorState extends State<ChecklistEditor>
children: itemTiles,
onReorder: (int oldIndex, int newIndex) {
setState(() {
/*
var item = todos.removeAt(oldIndex);
var item = checklist.removeAt(oldIndex);
if (newIndex > oldIndex) {
todos.insert(newIndex - 1, item);
checklist.insertItem(newIndex - 1, item);
} else {
todos.insert(newIndex, item);
checklist.insertItem(newIndex, item);
}
*/
});
},
);