diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json new file mode 100644 index 0000000..e1761a8 --- /dev/null +++ b/src/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/main.dart b/src/main.dart index deeaf98..abda782 100644 --- a/src/main.dart +++ b/src/main.dart @@ -1,8 +1,129 @@ -// TODO: Run task list app -void main(List args) { - print('Hello World'); +import 'dart:io'; +import 'task.dart'; +import 'taskList.dart'; + +//you can make it global so you can access it from anywhere +List _tasks = []; +TaskList tasks = TaskList([]); + +void main(List arg) { +//Listing Choices + void showTasks() { + print("This is your Task List app"); + print("**************************"); + print("What Do You Need?"); + print("1.Add Task"); + print("2.List Task"); + print("3.Update A Task"); + print("4.Delete A Task"); + print("5.Exit"); + } + +//Making Choice + int choice = 0; + while (choice != 5) { + showTasks(); + bool validChoice = false; + while (!validChoice) { + try { + stdout.write("Your Choice?"); + choice = int.parse(stdin.readLineSync()!); + validChoice = true; + } catch (e) { + print("Enter A Number:"); + } + } +//Operating Choice + switch (choice) { + case 1: + addTask(); + break; + case 2: + printTasks(); + break; + case 3: + choose(); + break; + case 4: + tasks.remove(); + break; + default: + print("Invalid Choice"); + break; + } + } +} + +//Choose Between Title && Description Update + +void choose() { + int choice = 0; + try { + stdout.write("To Change Title:1 / To Change Description:2 \n Your Choice?"); + choice = int.parse(stdin.readLineSync()!); + //validChoice = true; + } catch (e) { + print("Enter A Number:"); + } + switch (choice) { + case 1: + updateTitle(_tasks); + break; + case 2: + updateDescription(_tasks); + break; + default: + print("Invalid Choice"); + break; + } +} + +//Adding A Task +void addTask() { + stdout.write("Choose A Title For Your Task:"); + String? title = stdin.readLineSync() ?? ""; + if (title == "") { + print("You Should Enter A Title:"); + return; + } + stdout.write("Choose A Description For Your Task:"); + String? description = stdin.readLineSync() ?? ""; + if (description == "") { + print("You Should Enter A Description"); + return; + } + tasks.addTask(title, description); +} + +//Viewing Tasks +void printTasks() { + print(tasks.toString()); +} + +//For Title Update +void updateTitle(_tasks) { + stdout.write("What Task To Update?"); + int taskID = int.parse(stdin.readLineSync()!); + if (taskID <= tasks.length && taskID > 0) { + stdout.write("Enter Your New Title:"); + String? Title = stdin.readLineSync(); + tasks[taskID].title = Title!; + print("Updated Successfuly"); + print("New Title:" '${tasks[taskID].title}'); + return; + } } -class TaskListApp { - // TODO: Implement Task list app +//For Description Update +void updateDescription(_tasks) { + stdout.write("What Task To Update?"); + int taskID = int.parse(stdin.readLineSync()!); + if (taskID <= tasks.length && taskID > 0) { + stdout.write("Enter Your New Description:"); + String? Description = stdin.readLineSync(); + tasks[taskID].description = Description!; + print("Updated Successfuly"); + print("New Description:" '${tasks[taskID].description}'); + return; + } } diff --git a/src/task.dart b/src/task.dart new file mode 100644 index 0000000..3188a21 --- /dev/null +++ b/src/task.dart @@ -0,0 +1,36 @@ +class Task { + int id; + String title; + String description; + bool isCompleted; + + void set Id(int id) { + this.id = id; + } + + int get Id { + return id; + } + + void set Title(String title) { + this.title = title; + } + + String get Title { + return title; + } + + void set Description(String description) { + this.description = description; + } + + String get Description { + return description; + } + + Task( + {this.id = 1, + required this.title, + required this.description, + this.isCompleted = false}); +} diff --git a/src/taskList.dart b/src/taskList.dart new file mode 100644 index 0000000..9964da4 --- /dev/null +++ b/src/taskList.dart @@ -0,0 +1,45 @@ +import 'task.dart'; +import 'dart:io'; + +class TaskList { + List _tasks = []; + TaskList(this._tasks); + Task operator [](int taskID) { + return _tasks[taskID]; + } + + int get length { + return _tasks.length; + } + //List get tasks => _tasks; + + void addTask(String title, String description) { + _tasks.add(Task(id: _tasks.length, title: title, description: description)); + } + + @override + String toString() { + String show = ""; + for (var task in _tasks) { + show += "`````````````````````````````\n"; + show += "Task ID:${task.id}\n"; + show += "Task Title:${task.title}\n"; + show += "Task Description:${task.description}\n"; + show += "Task Status:${task.isCompleted ? "Done" : "Not Done"}\n"; + show += "`````````````````````````````\n"; + } + return show; + } + + void remove() { + try { + stdout.write("If you want to remove a task enter its number:"); + int taskId = int.parse(stdin.readLineSync()!); + _tasks.removeWhere((tasks) => tasks.id == taskId); + print("Successfuly removed"); + } catch (e) { + print("Invalid ID"); + return; + } + } +}