From 2f8dd95ee9975305fe9c89df92612fb5e85fe0ca Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 23 Jan 2019 11:47:46 +0100 Subject: [PATCH] Note: Never let the created be null Null paramters are annoying, cause we then need to check if != null all the time. I hate this about Dart. A type should always have sensible defaults. --- lib/note.dart | 4 ++++ lib/storage/serializers.dart | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/note.dart b/lib/note.dart index fb4e558a..36c41ecd 100644 --- a/lib/note.dart +++ b/lib/note.dart @@ -12,6 +12,10 @@ class Note implements Comparable { Map extraProperties = new Map(); Note({this.created, this.body, this.fileName, this.extraProperties}) { + assert(this.created != null); + assert(this.body != null); + assert(this.fileName != null); + if (extraProperties == null) { extraProperties = new Map(); } diff --git a/lib/storage/serializers.dart b/lib/storage/serializers.dart index f65ad93c..e0baaf7d 100644 --- a/lib/storage/serializers.dart +++ b/lib/storage/serializers.dart @@ -28,7 +28,7 @@ class MarkdownYAMLSerializer implements NoteSerializer { var parts = str.split("---\n"); var yamlMap = loadYaml(parts[1]); - Map map = new Map(); + var map = new Map(); yamlMap.forEach((key, value) { map[key] = value; }); @@ -37,7 +37,9 @@ class MarkdownYAMLSerializer implements NoteSerializer { return new Note.fromJson(map); } - return new Note(body: str); + var map = new Map(); + map['body'] = str; + return new Note.fromJson(map); } @override