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 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 createNote(String content) async { if (content.isEmpty) { return; } await DB.db.insert('notes', {'content': content}); } Future updateNote(Note note) async { await DB.db.update( 'notes', {'content': note.content}, where: 'date = ?', whereArgs: [note.date], ); } Future 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 createTodo(String content) async { if (content.isEmpty) { return; } await DB.db.insert('todos', {'content': content}); }