From 3ef7f65b33baf236a97c4e40cb7ddee5b567577a Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 31 Jul 2021 14:59:23 +0200 Subject: [PATCH] SortingMode: Handle cases where one fileLastModified is null This is a mess. The entire Note class needs to be split up, and the file last modified should never be null. --- lib/core/sorting_mode.dart | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/core/sorting_mode.dart b/lib/core/sorting_mode.dart index 9d1506cf..41024360 100644 --- a/lib/core/sorting_mode.dart +++ b/lib/core/sorting_mode.dart @@ -1,3 +1,19 @@ +/* +Copyright 2020-2021 Vishesh Handa + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + import 'package:easy_localization/easy_localization.dart'; import 'package:gitjournal/core/note.dart'; @@ -172,7 +188,15 @@ int _sortModifiedDesc(Note a, Note b) { } if (bDt == null && aDt == null) { if (a.fileLastModified != null && b.fileLastModified != null) { - return a.fileLastModified!.compareTo(b.fileLastModified!); + if (a.fileLastModified == null && b.fileLastModified != null) { + return 1; + } else if (a.fileLastModified != null && b.fileLastModified == null) { + return -1; + } else if (a.fileLastModified != null && b.fileLastModified != null) { + return a.fileLastModified!.compareTo(b.fileLastModified!); + } else { + return a.fileName.compareTo(b.fileName); + } } else { return a.fileName.compareTo(b.fileName); }