Skip to content

Faris Alzayed - Task 2 Project#3

Open
FarisAI24 wants to merge 1 commit intoProgramming-Club-IAU:masterfrom
FarisAI24:master
Open

Faris Alzayed - Task 2 Project#3
FarisAI24 wants to merge 1 commit intoProgramming-Club-IAU:masterfrom
FarisAI24:master

Conversation

@FarisAI24
Copy link

No description provided.

Copy link

@Radwan-Albahrani Radwan-Albahrani left a comment

Choose a reason for hiding this comment

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

Very good work. This task can now be completed but here are suggested changes that could make the task better.

Comment on lines 81 to 105
class TaskListApp {
// TODO: Implement Task list app
int id;
String name;
String description;
bool isCompleted;

TaskListApp(
{required this.id,
required this.name,
required this.description,
this.isCompleted = false});

void markAsCompleted() {
isCompleted = true;
}

void markAsIncomplete() {
isCompleted = false;
}

@override
String toString() {
return 'Task ID: $id\nTask: $name\nDescription: $description\nCompleted: $isCompleted\n';
}
}

Choose a reason for hiding this comment

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

I would recommend code separation here. Put it in a different file

Comment on lines +26 to +33
// Add a task
print('Enter task name:');
String name = stdin.readLineSync()!;
print('Enter task description:');
String description = stdin.readLineSync()!;
tasks.add(
TaskListApp(id: ++taskId, name: name, description: description));
break;

Choose a reason for hiding this comment

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

Make the cases all functions instead

print('Enter task description:');
String description = stdin.readLineSync()!;
tasks.add(
TaskListApp(id: ++taskId, name: name, description: description));

Choose a reason for hiding this comment

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

Before adding a task, null check. If i press enter and its empty it shouldnt let me continue

case '2':
// Add a task
print('Enter task name:');
String name = stdin.readLineSync()!;

Choose a reason for hiding this comment

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

Suggested change
String name = stdin.readLineSync()!;
String name = stdin.readLineSync()!;
if(name.isNotEmpty || name == "")
{
print("Please enter a valid title")
}

Comment on lines +36 to +64
try {
print('Enter task ID:');
int id = int.parse(stdin.readLineSync()!);
TaskListApp? taskToUpdate = tasks.firstWhere((task) => task.id == id);
print('Enter new task name (leave blank to keep current name):');
String? name = stdin.readLineSync();
print(
'Enter new task description (leave blank to keep current description):');
String? description = stdin.readLineSync();
print(
'Would you like to mark this task as completed? (1 for yes, 0 for no)');
String? completed = stdin.readLineSync();
if (completed == '1') {
taskToUpdate.markAsCompleted();
}
if (completed == '0') {
taskToUpdate.markAsIncomplete();
}
if (name != null && name.isNotEmpty) {
taskToUpdate.name = name;
}

if (description != null && description.isNotEmpty) {
taskToUpdate.description = description;
}
} catch (e) {
print('Task not found, please enter a valid task ID.');
}
break;

Choose a reason for hiding this comment

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

Same thing, pull to a function instead

// Remove a task
print('Enter task ID:');
int id = int.parse(stdin.readLineSync()!);
tasks.removeWhere((task) => task.id == id);

Choose a reason for hiding this comment

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

very good use of removeWhere. Maybe add a check where if the list is still the same length then ID is wrong

@FarisAI24 FarisAI24 changed the title Task 2 Project - feedback needed. Faris - Task 2 Project Oct 5, 2023
@FarisAI24 FarisAI24 changed the title Faris - Task 2 Project Faris Alzayed - Task 2 Project Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants