Rename todo to scratch
This commit is contained in:
@@ -21,13 +21,13 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_notes_date_unique ON notes (date);
|
||||
-- ie. they're not really a list but instead a string
|
||||
-- But we will also keep a history of all todos
|
||||
-- Because we might as well
|
||||
CREATE TABLE IF NOT EXISTS todos (
|
||||
CREATE TABLE IF NOT EXISTS scratches (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_todos_date ON todos (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
||||
CREATE INDEX IF NOT EXISTS idx_scratches_date ON scratches (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
|
||||
''';
|
||||
|
||||
static Future<String> _getDatabasePath() async {
|
||||
|
@@ -11,6 +11,7 @@ import 'package:audioplayers/audioplayers.dart';
|
||||
// TODO: Add an entry field for the duration ie. the interval of apperance
|
||||
// TODO: Also the sound file, if possible...
|
||||
// TODO: Cram the above into the database
|
||||
// TODO: Implement some sort of scroll through notes
|
||||
|
||||
const Duration popupInterval = Duration(minutes: 20);
|
||||
const String notificationSound = 'MeetTheSniper.mp3';
|
||||
@@ -133,7 +134,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
TextEditingController();
|
||||
final TextEditingController _currentEntryController = TextEditingController();
|
||||
final FocusNode _currentEntryFocusNode = FocusNode();
|
||||
final TextEditingController _todoController = TextEditingController();
|
||||
final TextEditingController _scratchController = TextEditingController();
|
||||
|
||||
Note? previousNote;
|
||||
|
||||
@@ -159,7 +160,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
_previousEntryController.dispose();
|
||||
_currentEntryController.dispose();
|
||||
_currentEntryFocusNode.dispose();
|
||||
_todoController.dispose();
|
||||
_scratchController.dispose();
|
||||
_audioPlayer.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -232,25 +233,27 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
previousNote = note;
|
||||
_previousEntryController.text = note?.content ?? "";
|
||||
|
||||
final todo = await getLatestTodo();
|
||||
_todoController.text = todo?.content ?? "";
|
||||
final scratch = await getLatestScratch();
|
||||
_scratchController.text = scratch?.content ?? "";
|
||||
_currentEntryController.text = "";
|
||||
|
||||
debugPrint("Data loaded (placeholder).");
|
||||
debugPrint("Data loaded.");
|
||||
}
|
||||
|
||||
void _saveData() async {
|
||||
String previousEntry = _previousEntryController.text;
|
||||
String currentEntry = _currentEntryController.text;
|
||||
String todoList = _todoController.text;
|
||||
String scratchContent = _scratchController.text;
|
||||
|
||||
await createNote(currentEntry);
|
||||
await createTodo(todoList);
|
||||
await createScratch(scratchContent);
|
||||
if (previousNote != null) {
|
||||
previousNote!.content = previousEntry;
|
||||
await updateNote(previousNote!);
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
"Saving data (placeholder)... Current Entry: [${currentEntry.length} chars], Todo: [${todoList.length} chars]",
|
||||
"Saving data... Current Entry: [${currentEntry.length} chars], Scratch: [${scratchContent.length} chars]",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -319,7 +322,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: TextField(
|
||||
controller: _todoController,
|
||||
controller: _scratchController,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
style:
|
||||
@@ -327,7 +330,7 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
context,
|
||||
).textTheme.bodyMedium, // Apply theme text style
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Todo',
|
||||
labelText: 'Scratch',
|
||||
// border: OutlineInputBorder(), // Handled by theme
|
||||
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
|
||||
),
|
||||
|
@@ -7,11 +7,11 @@ class Note {
|
||||
Note({required this.date, required this.content});
|
||||
}
|
||||
|
||||
class Todo {
|
||||
class Scratch {
|
||||
final String date;
|
||||
final String content;
|
||||
String content;
|
||||
|
||||
Todo({required this.date, required this.content});
|
||||
Scratch({required this.date, required this.content});
|
||||
}
|
||||
|
||||
Future<Note?> getLatestNote() async {
|
||||
@@ -43,19 +43,21 @@ Future<void> updateNote(Note note) async {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Todo?> getLatestTodo() async {
|
||||
final todo = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM todos ORDER BY date DESC LIMIT 1',
|
||||
Future<Scratch?> getLatestScratch() async {
|
||||
final scratch = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM scratches ORDER BY date DESC LIMIT 1',
|
||||
);
|
||||
if (todo.isEmpty) {
|
||||
|
||||
if (scratch.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Todo(
|
||||
date: todo[0]['date'] as String,
|
||||
content: todo[0]['content'] as String,
|
||||
} else {
|
||||
return Scratch(
|
||||
date: scratch[0]['date'] as String,
|
||||
content: scratch[0]['content'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createTodo(String content) async {
|
||||
await DB.db.insert('todos', {'content': content});
|
||||
Future<void> createScratch(String content) async {
|
||||
await DB.db.insert('scratches', {'content': content});
|
||||
}
|
||||
|
Reference in New Issue
Block a user