Skip to content
Open

task #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 76 additions & 4 deletions src/core/note_app.dart
Original file line number Diff line number Diff line change
@@ -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<NoteModel> 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.");
}
}
1 change: 0 additions & 1 deletion src/core/utils.dart

This file was deleted.

48 changes: 45 additions & 3 deletions src/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
import 'dart:io';
import 'core/note_app.dart';

void main(List<String> 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.');
}
}
}



8 changes: 6 additions & 2 deletions src/models/note_model.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
//TODO: Define a note model class
class NoteModel {}
class NoteModel {
String? title;
String? context;
NoteModel({this.title, this.context});

}