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
13 changes: 13 additions & 0 deletions src/.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"
}
]
}
131 changes: 126 additions & 5 deletions src/main.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 = [];

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

Suggested change
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?");

Choose a reason for hiding this comment

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

could make this prettier

Suggested change
stdout.write("Your Choice?");
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?");

Choose a reason for hiding this comment

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

Could make this prettier

Suggested change
stdout.write("To Change Title:1 / To Change Description:2 \n Your Choice?");
stdout.write("1. Change Title\n2. Change Description\n Your Choice: ");

choice = int.parse(stdin.readLineSync()!);
//validChoice = true;
} catch (e) {
print("Enter A Number:");
}
switch (choice) {
case 1:
updateTitle(_tasks);

Choose a reason for hiding this comment

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

unnecessary variable

Suggested change
updateTitle(_tasks);
updateTitle();

or if you move it to the TaskList Class

Suggested change
updateTitle(_tasks);
tasks.updateTitle();

break;
case 2:
updateDescription(_tasks);

Choose a reason for hiding this comment

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

unnecessary variable

Suggested change
updateDescription(_tasks);
updateDescription();

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) {

Choose a reason for hiding this comment

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

unnecessary variable

Suggested change
void updateTitle(_tasks) {
void updateTitle() {

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!;

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

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

unnecessary variable

Suggested change
void updateDescription(_tasks) {
void updateDescription() {

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;
}
}
36 changes: 36 additions & 0 deletions src/task.dart
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});
}
45 changes: 45 additions & 0 deletions src/taskList.dart
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

Choose a reason for hiding this comment

The 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;
}
}
}