Conversation
Radwan-Albahrani
left a comment
There was a problem hiding this comment.
Very good work. Fix the above mentioned mistakes and it'll be even better. Also, in your vscode, enable format on save. Your file formatting has a bunch of empty spaces and misaligned brackets and tabs.
src/task_list.dart
Outdated
| new_task.ID = All_tasks.length; | ||
|
|
||
| stdout.write('task title: '); | ||
| new_task.Title = stdin.readLineSync()!; |
There was a problem hiding this comment.
Should add null safety to this
| new_task.Title = stdin.readLineSync()!; | |
| String? title = stdin.readLineSync() ?? "" | |
| if(title == "") | |
| { | |
| stdout.write("Title Invalid") | |
| } |
Maybe add a while loop or a try catch to keep the user in this state until a title is given
src/task_list.dart
Outdated
| new_task.Title = stdin.readLineSync()!; | ||
|
|
||
| stdout.write('task description: '); | ||
| new_task.Description = stdin.readLineSync()!; |
src/task_list.dart
Outdated
| stdout.write('Please enter the ID of the task you want to remove: '); | ||
| int task_id = int.parse(stdin.readLineSync()!); | ||
|
|
||
| All_tasks.remove(All_tasks[task_id]); |
There was a problem hiding this comment.
Check the ID before removing. Could Cause index out of bounds exception
src/task_list.dart
Outdated
| stdout.write('Please enter the ID of the task you want to update: '); | ||
| int task_id = int.parse(stdin.readLineSync()!); | ||
|
|
||
| Task the_task = All_tasks[task_id]; |
src/task_list.dart
Outdated
| Task the_task = All_tasks[task_id]; | ||
|
|
||
| stdout.write('What do you want to update (title, description, completed)?'); | ||
| String? field = stdin.readLineSync()!; |
src/task_list.dart
Outdated
| stdout.write('Enter new description please: '); | ||
| the_task.Description = stdin.readLineSync()!; | ||
| } | ||
| else if (field == 'competed') |
|
Seems all things have been resolved. great work! |
src/task_list.dart
Outdated
| List<Task> All_tasks = []; | ||
|
|
There was a problem hiding this comment.
please read the following https://dart.dev/effective-dart/style for naming in dart.
the variable name should be allTasks
| List<Task> All_tasks = []; | |
| List<Task> allTasks = []; | |
| class Task { | ||
|
|
||
| late int ID; | ||
| late String Title; | ||
| late String Description; | ||
| late bool isCompleted; | ||
|
|
||
| Task(this.ID, this.Title, this.Description, this.isCompleted); | ||
|
|
||
| Task.create() { | ||
| ID = 0; | ||
| Title = ''; | ||
| Description = ''; | ||
| isCompleted = false; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
here you should follow the naming convention for variables.
use "late" only when necessary you could replace it by making constructor required for example:
| class Task { | |
| late int ID; | |
| late String Title; | |
| late String Description; | |
| late bool isCompleted; | |
| Task(this.ID, this.Title, this.Description, this.isCompleted); | |
| Task.create() { | |
| ID = 0; | |
| Title = ''; | |
| Description = ''; | |
| isCompleted = false; | |
| } | |
| } | |
| Task({ | |
| required this.id, | |
| required this.title, | |
| required this.description, | |
| required this.isCompleted, | |
| }); |
you can use factory method too :
| class Task { | |
| late int ID; | |
| late String Title; | |
| late String Description; | |
| late bool isCompleted; | |
| Task(this.ID, this.Title, this.Description, this.isCompleted); | |
| Task.create() { | |
| ID = 0; | |
| Title = ''; | |
| Description = ''; | |
| isCompleted = false; | |
| } | |
| } | |
| factory Task.create() { | |
| return Task( | |
| id: 0, | |
| title: '', | |
| description: '', | |
| isCompleted: false, | |
| ); | |
| } | |
No description provided.