mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Checklist: Let items be re-ordered
This commit is contained in:
@ -82,6 +82,32 @@ class Checklist {
|
|||||||
nodes.remove(item.element);
|
nodes.remove(item.element);
|
||||||
items.remove(item);
|
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
|
/// Copied from flutter-markdown - cannot be merged as we added xUpperCase and changed the regexp
|
||||||
|
@ -73,15 +73,13 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
|||||||
children: itemTiles,
|
children: itemTiles,
|
||||||
onReorder: (int oldIndex, int newIndex) {
|
onReorder: (int oldIndex, int newIndex) {
|
||||||
setState(() {
|
setState(() {
|
||||||
/*
|
var item = checklist.removeAt(oldIndex);
|
||||||
var item = todos.removeAt(oldIndex);
|
|
||||||
|
|
||||||
if (newIndex > oldIndex) {
|
if (newIndex > oldIndex) {
|
||||||
todos.insert(newIndex - 1, item);
|
checklist.insertItem(newIndex - 1, item);
|
||||||
} else {
|
} else {
|
||||||
todos.insert(newIndex, item);
|
checklist.insertItem(newIndex, item);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user