Skip to content

Commit 4a322b6

Browse files
committed
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.
1 parent 2821eb1 commit 4a322b6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/core/note_serializer.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ class NoteSerializer implements NoteSerializerInterface {
2929
else
3030
data.props.remove(settings.modifiedKey);
3131

32-
if (note.title != null && note.title.isNotEmpty)
33-
data.props[settings.titleKey] = note.title;
32+
if (note.title != null) {
33+
var title = note.title.trim();
34+
if (title.isNotEmpty)
35+
data.props[settings.titleKey] = note.title;
36+
else
37+
data.props.remove(settings.titleKey);
38+
} else
39+
data.props.remove(settings.titleKey);
3440

3541
data.body = note.body;
3642
}
@@ -40,6 +46,6 @@ class NoteSerializer implements NoteSerializerInterface {
4046
note.body = data.body;
4147
note.created = parseDateTime(data.props[settings.createdKey]?.toString());
4248
note.modified = parseDateTime(data.props[settings.modifiedKey]?.toString());
43-
note.title = data.props[settings.titleKey]?.toString();
49+
note.title = data.props[settings.titleKey]?.toString() ?? "";
4450
}
4551
}

0 commit comments

Comments
 (0)