diff --git a/lib/core/notes_cache.dart b/lib/core/notes_cache.dart index bba658ec..35a17e55 100644 --- a/lib/core/notes_cache.dart +++ b/lib/core/notes_cache.dart @@ -121,6 +121,10 @@ class NotesCache { rethrow; } + if (contents.isEmpty) { + return []; + } + try { return json.decode(contents).cast(); } catch (ex, st) { @@ -131,8 +135,12 @@ class NotesCache { } @visibleForTesting - Future saveToDisk(List files) { + Future saveToDisk(List files) async { var contents = json.encode(files); - return File(filePath).writeAsString(contents); + var newFilePath = filePath + ".new"; + + var file = File(newFilePath); + await file.writeAsString(contents); + await file.rename(filePath); } }