Skip to content
Open
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
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file not shown.
Binary file added .vs/Selection-Project/v17/.wsuo
Binary file not shown.
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\src",
"\\src\\core",
"\\src\\models"
],
"SelectedNode": "\\src\\core\\note_app.dart",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dart & Flutter",
"request": "launch",
"type": "dart"
}
]
}
128 changes: 128 additions & 0 deletions src/core/Note.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import 'note_app.dart';
class Note {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating the note title and content into the note_model.dart file, and place note functions in a NoteManager class for better readability.


String? Title, Content;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using non-nullable types for your class properties if possible. This can help catch potential null-related errors during development.

String title;
String content;

Note.create({required this.title, required this.content});




Note(String? title, String? content){
this.Title= title;
this.Content=content;
}


void setTtile(String? Title){
this.Title=Title;
}

void setContent(String? Content){
this.Content=Content;
}

String? getTitle(){
return Title;
}

String? getContent(){
return Content;
}

static List<Note> NotesList =[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses camelCase
notesList


static void CreateNote(Note newNote){

NotesList.add(newNote);
print("Note added sucessfuly");

}

static void deleteNoteM(String? delNoteV){
bool found=false;
for (int i =0; i<NotesList.length ;i++){

if (NotesList[i].Title== delNoteV){
found =true;
NotesList.removeAt(i);
print("note was deleted sucessfully");
break;
}

}
if(!found){
print("note wasn't found");
}

}

static void editTitleM(String? toEdit ,String? editNoteV){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The methods editTitleM and editContentM have similar logic. You could consider refactoring the common logic into a method to avoid code duplication.


bool found=false;
for (int i =0; i<NotesList.length ;i++){
if (NotesList[i].Title== toEdit){
found =true;
NotesList[i].setTtile(editNoteV);
print("note was edited sucessfully");
break;
}

}
if(!found){
print("note wasn't found");
}
}


static void editContentM(String? toEdit ,String? editNoteV){

bool found=false;
for (int i =0; i<NotesList.length ;i++){
if (NotesList[i].Title== toEdit){
found =true;
NotesList[i].setContent(editNoteV);
print("note was edited sucessfully");
break;
}

}
if(!found){
print("note wasn't found");
}
}

static void searchByTitleM(String? title){
bool found=false;
for (int i =0; i<NotesList.length ;i++){
if (NotesList[i].Title== title){
found =true;
print("Note is found! \n =============== \n Content: \n ===============");
print(NotesList[i].Content);
break;
}

}
if(!found){
print("note wasn't found");
}
}

static void searchByContentM(String? content){
bool found=false;
for (int i =0; i<NotesList.length ;i++){
if (NotesList[i].Content== content){
found =true;
print("Note is found! \n ============ \n Title: ");
print(NotesList[i].Title);
break;
}

}
if(!found){
print("note wasn't found");
}
}

}




125 changes: 123 additions & 2 deletions src/core/note_app.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,127 @@
import 'dart:io';
import 'Note.dart';
String? delNoteV, editNoteV, toEdit;

class NoteApp {
// TODO: Complete the run function

void run() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating different functionalities into separate methods.

if (operation > 0 && operation < 7) {
    switch (operation) {
        case 1:
            createNote();
            break;
        case 2:
            editNote();
            break;
        case 3:
            deleteNote();
            break;
        case 4:
            printNotes();
            break;
        case 5:
            searchNote();
            break;
        case 6:
            print("Exiting Note Taking App.");
            break;
        default:
            print("Invalid choice. Please enter a number between 1 to 6.");
            break;
    }
} else {
    print("Invalid choice. Please enter a number between 1 to 6.");
} 
} while (operation != 6);

print('Hello, world!');


int operation ;
do {
print(" \nNOTE TAKING APP \n \n ***************** \n 1- Create a note \n 2- Edit a note \n 3- Delete a note \n 4- Print notes \n 5- Search for a note \n 6- Exit \n ***************** \n ");

print ("Choose an operation ");
operation = int.parse(stdin.readLineSync()!);
if (operation>0 && operation <7){
switch (operation) {

case 1:
//create a note
try{
String? newNoteTitle;
String? newNoteContent;

print("Title: \n ****");
newNoteTitle = stdin.readLineSync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if the title already exists before adding the note or if the title is empty.


print ("content: \n ****");
newNoteContent = stdin.readLineSync();

Note newNote= Note(newNoteTitle,newNoteContent);
Note.CreateNote(newNote);
break;} catch (e){
print ("invalid input");
}
case 2: {
//Edit a note's title or content

print("To edit the title press (1), Content press (2)");
try {
int editSwitch= int.parse(stdin.readLineSync()!);
switch (editSwitch) {
case 1 : print ("Enter the title of the note to edit: ") ;
toEdit=stdin.readLineSync();
print ("enter the new title: ");
editNoteV= stdin.readLineSync();
Note.editTitleM(toEdit,editNoteV);
break;

case 2:
print ("Enter the title of the note to edit: ") ;
toEdit=stdin.readLineSync();
print ("enter the new Cotent: ");
editNoteV= stdin.readLineSync();
Note.editContentM(toEdit,editNoteV);
break;

default:
print ("invalid input");
}} catch(e){
print ("invalid input");
}}
break;

case 3:
//Delete a note
try{
print("Write the title of the note to delete: ");
delNoteV= stdin.readLineSync();
Note.deleteNoteM(delNoteV);
break;
} catch (e){
print ("invalid input");
}
case 4:
// print all notes
try{
print("\n All Notes:");
print(" _______________________ ");

for (var i = 0; i < Note.NotesList.length; i++) {
print(" | |");
print(" | Title: ${Note.NotesList[i].Title}");
print(" | Content: ${Note.NotesList[i].Content} ");
print(" | | ");
print(" |______________________| ");
}
break;}
catch (e){
print ("invalid input");
}
case 5:
//searsh BY titile OR content

print("To search by title press (1) and to search by Content press (2)");
try {
int searchSwitch= int.parse(stdin.readLineSync()!);
switch (searchSwitch) {
case 1 :
print ("Enter the title of the note: ") ;
toEdit=stdin.readLineSync();
Note.searchByTitleM(toEdit);
break;

case 2:
print ("Enter the content of the note: ") ;
toEdit=stdin.readLineSync();
Note.searchByContentM(toEdit);
break;

default:
print("Invalid choice");

}} catch(e){
print ("invalid input");
}
break;


default:
exit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use break to exit the loop and let the loop condition handle the exit.


}}
} while ( operation!=6);

}
}
Empty file.
9 changes: 9 additions & 0 deletions src/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import 'core/note_app.dart';




void main(List<String> args) {



NoteApp().run();



}
14 changes: 13 additions & 1 deletion src/models/note_model.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
//TODO: Define a note model class
class NoteModel {}
class NoteModel {
String? name;
String? content;


NoteModel({this.name, this.content});

String? Create (String name , String content){

return name+content;
}

}
Empty file added src/tempCodeRunnerFile.dart
Empty file.