From 140954e7d1c2bf56cb9f9909c1ca02f0f2065bd9 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 18 May 2020 00:42:15 +0200 Subject: [PATCH] ChecklistEditor: Remove trailing empty items --- lib/editors/checklist_editor.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/editors/checklist_editor.dart b/lib/editors/checklist_editor.dart index 7173e860..dea03ec7 100644 --- a/lib/editors/checklist_editor.dart +++ b/lib/editors/checklist_editor.dart @@ -181,13 +181,17 @@ class ChecklistEditorState extends State @override Note getNote() { - var note = checklist.note; - if (checklist.items.length == 1) { - var item = checklist.items.first; - if (item.checked == false && item.text.trim().isEmpty) { - note.body = ""; + // Remove trailing empty items + while (checklist.items.isNotEmpty) { + var last = checklist.items.last; + if (last.checked == false && last.text.trim().isEmpty) { + checklist.removeAt(checklist.items.length - 1); + } else { + break; } } + + var note = checklist.note; note.title = _titleTextController.text.trim(); note.type = NoteType.Checklist; return note;