diff --git a/src/core/note_app.dart b/src/core/note_app.dart index 39a3f92..eb2e0a0 100644 --- a/src/core/note_app.dart +++ b/src/core/note_app.dart @@ -1,6 +1,78 @@ -class NoteApp { - // TODO: Complete the run function - void run() { - print('Hello, world!'); +import 'dart:io'; +import '../models/note_model.dart'; + class NoteApp { + List notes = []; + + void Menu() { + print("----------MENU----------"); + print("1-Creat a note"); + print("2-Edit a note"); + print("3-Delete a note"); + print("4-Search for note"); + print("5-Exit"); + print("------------------------"); + } + + void creat_note() { + print("Enter the title:"); + String? title = stdin.readLineSync(); + print("Enter the note context:"); + String? context = stdin.readLineSync(); + notes.add(NoteModel(title: title, context: context)); + print("note added."); + print('Title: ${notes[notes.length - 1].title}'); + } + + void edit_note() { + if (notes.isEmpty) { + print("there is nothing to edit."); + return; + } + print("enter the index of the note you want to edit:"); + int? index = int.tryParse(stdin.readLineSync() ?? ''); + if (index == null || notes.length <= index || index < 0) { + print("this index is invalid."); + return; + } + print("Enter the new title: "); + String? new_title = stdin.readLineSync(); + notes[index].title = new_title; + print("Enter the new note context: "); + String? new_context = stdin.readLineSync(); + notes[index].context = new_context; + print("your note is edited."); + } + + void delete_note() { + if (notes.isEmpty) { + print("there is nothing to delete."); + return; + } + print("enter the index of the note you want to delete:"); + int? index = int.tryParse(stdin.readLineSync() ?? ''); + if (index == null || notes.length <= index || index < 0) { + print("this index is invalid."); + return; + } + notes.remove(index); + print("your note is deleted."); + } + + void search_note() { + if (notes.isEmpty) { + print("there is nothing to edit."); + return; + } + print("Enter the title for the note that you want to search for: "); + String? title = stdin.readLineSync(); + for (int i = 0; i < notes.length; i++) { + if (notes[i].title == title) { + print("your note is found."); + print('Title: ${notes[i].title}'); + print('note context: ${notes[i].context}'); + return; + } + } + print("your note isnt found."); } } diff --git a/src/core/utils.dart b/src/core/utils.dart deleted file mode 100644 index 289a24d..0000000 --- a/src/core/utils.dart +++ /dev/null @@ -1 +0,0 @@ -// TODO: Add any utility functions here \ No newline at end of file diff --git a/src/main.dart b/src/main.dart index 88398d1..381a219 100644 --- a/src/main.dart +++ b/src/main.dart @@ -1,5 +1,47 @@ +import 'dart:io'; import 'core/note_app.dart'; -void main(List args) { - NoteApp().run(); -} +void main() { + print("----------MENU----------"); + print("1-Creat a note"); + print("2-Edit a note"); + print("3-Delete a note"); + print("4-Search for note"); + print("5-Exit"); + print("------------------------"); + while (true) { + stdout.write('Enter your choice: '); + String? input = stdin.readLineSync(); + if (input != null && input.isNotEmpty) { + int? choice = int.tryParse(input); + if (choice != null) { + switch (choice) { + case 1: + creat_note(); + break; + case 2: + edit_note(); + break; + case 3: + delete_note(); + break; + case 4: + search_note(); + break; + case 5: + exit(0); + break; + default: + print('Invalid choice.'); + } + } else { + print('Please enter a valid number.'); + } + } else { + print('Please enter a choice.'); + } + } + } + + + diff --git a/src/models/note_model.dart b/src/models/note_model.dart index 788b69e..ad243a2 100644 --- a/src/models/note_model.dart +++ b/src/models/note_model.dart @@ -1,2 +1,6 @@ -//TODO: Define a note model class -class NoteModel {} +class NoteModel { + String? title; + String? context; + NoteModel({this.title, this.context}); + +} \ No newline at end of file