From 4a322b6fc489d8b25883413779af1e93772f0d2f Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 1 Jan 2020 19:51:26 +0100 Subject: [PATCH] Note: The title should never be null Too much of the code assumes that it will never be null. It'll be so awesome when Dart allows you to enforce that a type is never null. --- lib/core/note_serializer.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index dbb6f299..ba174d42 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -29,8 +29,14 @@ class NoteSerializer implements NoteSerializerInterface { else data.props.remove(settings.modifiedKey); - if (note.title != null && note.title.isNotEmpty) - data.props[settings.titleKey] = note.title; + if (note.title != null) { + var title = note.title.trim(); + if (title.isNotEmpty) + data.props[settings.titleKey] = note.title; + else + data.props.remove(settings.titleKey); + } else + data.props.remove(settings.titleKey); data.body = note.body; } @@ -40,6 +46,6 @@ class NoteSerializer implements NoteSerializerInterface { note.body = data.body; note.created = parseDateTime(data.props[settings.createdKey]?.toString()); note.modified = parseDateTime(data.props[settings.modifiedKey]?.toString()); - note.title = data.props[settings.titleKey]?.toString(); + note.title = data.props[settings.titleKey]?.toString() ?? ""; } }