-
Notifications
You must be signed in to change notification settings - Fork 7
Zahra Alnamer #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6c33942
c28202a
da10dd9
a7ccb2b
6526dfb
393d285
6d85972
6e6bfa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,129 @@ | ||||||||||
| // TODO: Run task list app | ||||||||||
| void main(List<String> 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<Task> _tasks = []; | ||||||||||
| TaskList tasks = TaskList([]); | ||||||||||
|
|
||||||||||
| void main(List<String> 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?"); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could make this prettier
Suggested change
|
||||||||||
| 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?"); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could make this prettier
Suggested change
|
||||||||||
| choice = int.parse(stdin.readLineSync()!); | ||||||||||
| //validChoice = true; | ||||||||||
| } catch (e) { | ||||||||||
| print("Enter A Number:"); | ||||||||||
| } | ||||||||||
| switch (choice) { | ||||||||||
| case 1: | ||||||||||
| updateTitle(_tasks); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary variable
Suggested change
or if you move it to the TaskList Class
Suggested change
|
||||||||||
| break; | ||||||||||
| case 2: | ||||||||||
| updateDescription(_tasks); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary variable
Suggested change
|
||||||||||
| 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) { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary variable
Suggested change
|
||||||||||
| 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!; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while this method is smart, it allows for direct access to the task attributes without any security measures. Its why i recommended adding, updating, and removing directly from inside the TaskList class. This would ensure all the data preprocessing you will do including null checking and stuff happens before the title is changed |
||||||||||
| print("Updated Successfuly"); | ||||||||||
| print("New Title:" '${tasks[taskID].title}'); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class TaskListApp { | ||||||||||
| // TODO: Implement Task list app | ||||||||||
| //For Description Update | ||||||||||
| void updateDescription(_tasks) { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary variable
Suggested change
|
||||||||||
| 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; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import 'task.dart'; | ||
| import 'dart:io'; | ||
|
|
||
| class TaskList { | ||
| List<Task> _tasks = []; | ||
| TaskList(this._tasks); | ||
| Task operator [](int taskID) { | ||
| return _tasks[taskID]; | ||
| } | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smart way to add an operator to the taskList. Didnt even know that was possible 😂 |
||
|
|
||
| int get length { | ||
| return _tasks.length; | ||
| } | ||
| //List<Task> 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; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable is not necessary anymore