mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Add/Remove individual notes from disk
Instead of rewriting all of them on save.
This commit is contained in:
@ -59,4 +59,25 @@ class FileStorage {
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
Future<bool> addNote(Note note) async {
|
||||
final dir = await getDirectory();
|
||||
var filePath = p.join(dir.path, fileNameGenerator(note));
|
||||
|
||||
var file = new File(filePath);
|
||||
var contents = noteSerializer.encode(note);
|
||||
await file.writeAsString(contents);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> removeNote(Note note) async {
|
||||
final dir = await getDirectory();
|
||||
var filePath = p.join(dir.path, fileNameGenerator(note));
|
||||
|
||||
var file = new File(filePath);
|
||||
await file.delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -56,36 +56,32 @@ class StateContainerState extends State<StateContainer> {
|
||||
});
|
||||
}).catchError((err) {
|
||||
setState(() {
|
||||
print("Got Error");
|
||||
print("Load Notes Error:");
|
||||
print(err);
|
||||
appState.isLoading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(VoidCallback fn) {
|
||||
super.setState(fn);
|
||||
|
||||
fileStorage.saveNotes(appState.notes);
|
||||
}
|
||||
|
||||
void addNote(Note note) {
|
||||
setState(() {
|
||||
note.id = new Uuid().v4();
|
||||
appState.notes.insert(0, note);
|
||||
fileStorage.addNote(note);
|
||||
});
|
||||
}
|
||||
|
||||
void removeNote(Note note) {
|
||||
setState(() {
|
||||
appState.notes.remove(note);
|
||||
fileStorage.removeNote(note);
|
||||
});
|
||||
}
|
||||
|
||||
void insertNote(int index, Note note) {
|
||||
setState(() {
|
||||
appState.notes.insert(index, note);
|
||||
fileStorage.addNote(note);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user