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.
This commit is contained in:
Vishesh Handa
2019-01-23 11:47:46 +01:00
parent cdc6fd9ed7
commit 2f8dd95ee9
2 changed files with 8 additions and 2 deletions

View File

@ -12,6 +12,10 @@ class Note implements Comparable {
Map<String, dynamic> extraProperties = new Map<String, dynamic>();
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<String, dynamic>();
}

View File

@ -28,7 +28,7 @@ class MarkdownYAMLSerializer implements NoteSerializer {
var parts = str.split("---\n");
var yamlMap = loadYaml(parts[1]);
Map<String, dynamic> map = new Map<String, dynamic>();
var map = new Map<String, dynamic>();
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<String, dynamic>();
map['body'] = str;
return new Note.fromJson(map);
}
@override