From 3d12c833d384d4638c702b6ca88d904c0b63de02 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 6 Feb 2020 11:52:27 +0100 Subject: [PATCH] Revert "Deletes Note.compareTo" This reverts commit 6cf5454f7940c9aee65279c4635f84b04f9ec700. Having this compareTo makes testing easier. --- lib/core/note.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/core/note.dart b/lib/core/note.dart index 68dc6480..1e157301 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -16,7 +16,7 @@ enum NoteLoadState { NotExists, } -class Note with ChangeNotifier { +class Note with ChangeNotifier implements Comparable { NotesFolder parent; String _filePath; @@ -204,4 +204,19 @@ class Note with ChangeNotifier { String toString() { return 'Note{filePath: $_filePath, created: $created, modified: $modified, data: $_data}'; } + + @override + int compareTo(Note other) { + if (other == null) { + return -1; + } + + var dt = modified ?? created ?? _fileLastModified; + var otherDt = other.modified ?? other.created ?? other._fileLastModified; + if (dt == null || otherDt == null) { + return _filePath.compareTo(other._filePath); + } + + return dt.compareTo(otherDt); + } }