mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
Note class should not be sortable
There are various different methods of sorting an note.
This commit is contained in:
@ -18,7 +18,7 @@ enum NoteLoadState {
|
|||||||
NotExists,
|
NotExists,
|
||||||
}
|
}
|
||||||
|
|
||||||
class Note with ChangeNotifier implements Comparable<Note> {
|
class Note with ChangeNotifier {
|
||||||
NotesFolder parent;
|
NotesFolder parent;
|
||||||
String _filePath;
|
String _filePath;
|
||||||
|
|
||||||
@ -232,19 +232,4 @@ class Note with ChangeNotifier implements Comparable<Note> {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return 'Note{filePath: $_filePath, created: $created, modified: $modified, data: $_data}';
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,9 @@ void main() {
|
|||||||
loadedNotes.add(note);
|
loadedNotes.add(note);
|
||||||
});
|
});
|
||||||
|
|
||||||
loadedNotes.sort();
|
var sortFn = (Note n1, Note n2) => n1.filePath.compareTo(n2.filePath);
|
||||||
notes.sort();
|
loadedNotes.sort(sortFn);
|
||||||
|
notes.sort(sortFn);
|
||||||
|
|
||||||
expect(loadedNotes, notes);
|
expect(loadedNotes, notes);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user