Files
journaler/lib/notes.dart

65 lines
1.3 KiB
Dart

import 'package:journaler/db.dart';
class Note {
final String date;
String content;
Note({required this.date, required this.content});
}
class Todo {
final String date;
final String content;
Todo({required this.date, required this.content});
}
Future<Note?> getLatestNote() async {
final note = await DB.db.rawQuery(
'SELECT content, date FROM notes ORDER BY date DESC LIMIT 1',
);
if (note.isEmpty) {
return null;
}
return Note(
date: note[0]['date'] as String,
content: note[0]['content'] as String,
);
}
Future<void> createNote(String content) async {
if (content.isEmpty) {
return;
}
await DB.db.insert('notes', {'content': content});
}
Future<void> updateNote(Note note) async {
await DB.db.update(
'notes',
{'content': note.content},
where: 'date = ?',
whereArgs: [note.date],
);
}
Future<Todo?> getLatestTodo() async {
final todo = await DB.db.rawQuery(
'SELECT content, date FROM todos ORDER BY date DESC LIMIT 1',
);
if (todo.isEmpty) {
return null;
}
return Todo(
date: todo[0]['date'] as String,
content: todo[0]['content'] as String,
);
}
Future<void> createTodo(String content) async {
if (content.isEmpty) {
return;
}
await DB.db.insert('todos', {'content': content});
}