@@ -35,15 +35,15 @@ class Note with ChangeNotifier implements Comparable<Note> {
35
35
36
36
Note .newNote (this .parent) {
37
37
_created = DateTime .now ();
38
- _filePath = p.join (parent.folderPath, getFileName (this ));
39
38
}
40
39
41
40
String get filePath {
41
+ _filePath ?? = p.join (parent.folderPath, getFileName (this ));
42
42
return _filePath;
43
43
}
44
44
45
45
String get fileName {
46
- return p.basename (_filePath );
46
+ return p.basename (filePath );
47
47
}
48
48
49
49
DateTime get created {
@@ -104,11 +104,14 @@ class Note with ChangeNotifier implements Comparable<Note> {
104
104
}
105
105
106
106
Future <NoteLoadState > load () async {
107
+ assert (_filePath != null );
108
+ assert (_filePath.isNotEmpty);
109
+
107
110
if (_loadState == NoteLoadState .Loading ) {
108
111
return _loadState;
109
112
}
110
113
111
- final file = File (filePath );
114
+ final file = File (_filePath );
112
115
if (_loadState == NoteLoadState .Loaded ) {
113
116
var fileLastModified = file.lastModifiedSync ();
114
117
if (fileLastModified == _fileLastModified) {
@@ -134,7 +137,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
134
137
135
138
// FIXME: What about error handling?
136
139
Future <void > save () async {
137
- assert (filePath != null );
140
+ assert (_filePath != null );
138
141
assert (data != null );
139
142
assert (data.body != null );
140
143
assert (data.props != null );
@@ -146,24 +149,26 @@ class Note with ChangeNotifier implements Comparable<Note> {
146
149
147
150
// FIXME: What about error handling?
148
151
Future <void > remove () async {
149
- var file = File (filePath);
152
+ assert (_filePath != null );
153
+
154
+ var file = File (_filePath);
150
155
await file.delete ();
151
156
}
152
157
153
158
@override
154
- int get hashCode => filePath .hashCode;
159
+ int get hashCode => _filePath .hashCode;
155
160
156
161
@override
157
162
bool operator == (Object other) =>
158
163
identical (this , other) ||
159
164
other is Note &&
160
165
runtimeType == other.runtimeType &&
161
- filePath == other.filePath &&
166
+ _filePath == other._filePath &&
162
167
_data == other._data;
163
168
164
169
@override
165
170
String toString () {
166
- return 'Note{filePath: $filePath , created: $created , modified: $modified , data: $_data }' ;
171
+ return 'Note{filePath: $_filePath , created: $created , modified: $modified , data: $_data }' ;
167
172
}
168
173
169
174
@override
@@ -175,7 +180,7 @@ class Note with ChangeNotifier implements Comparable<Note> {
175
180
var dt = modified ?? created ?? _fileLastModified;
176
181
var otherDt = other.modified ?? other.created ?? other._fileLastModified;
177
182
if (dt == null || otherDt == null ) {
178
- return filePath .compareTo (other.filePath );
183
+ return _filePath .compareTo (other._filePath );
179
184
}
180
185
181
186
return dt.compareTo (otherDt);
0 commit comments