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
File renamed without changes.
116 changes: 116 additions & 0 deletions src/task.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'dart:io';

class Task {
int id;
String? title;
String? description;
bool isCompleted;

Task(this.id, this.title, this.description, this.isCompleted);
}

class TaskManager {
List<Task> tasks = [];
int id = 1;

//Add tasks
void addTask(String? title, String? description, bool isCompleted) {
tasks.add(Task(id, title, description,
isCompleted)); //takes constructor/object as a input

id++;

print("Task successfully added.");
print("\n****************************************");
}

//Display tasks
void display() {
print("\n**************Display tasks***************");
if (tasks.isNotEmpty) {
for (int i = 0; i < tasks.length; i++) {
Task task = tasks[i];
print(
"Task ID: ${task.id}\nTask name: ${task.title}\nTask Description: ${task.description}\nTask completed: ${task.isCompleted}");
print("\n*****************************************");
}
} else {
print("No tasks present.");
print("\n*******************************************");
}
}

//Delete tasks
void delete(taskid) {
print("\n**************Delete Task**************");
if (tasks.isNotEmpty) {
for (int i = 0; i < tasks.length; i++) {
Task task = tasks[i];
if (task.id == taskid) {
tasks.removeAt(i);
print("Task Removed Successfully.");
print("\n***************************************");
break;
} else if (i == tasks.length - 1) {
print("ID not present.");
print("\n***************************************");
}
}
} else {
print("No Task to delete.");
print("\n***************************************");
}
}

//Update tasks
void update(taskid) {
print("*****************Update Task*****************\n");
if (tasks.isNotEmpty) {
for (int i = 0; i < tasks.length; i++) {
Task task = tasks[i];
if (task.id == taskid) {
print("What do you want to update:");
print("1)Title\n2)Description\n3)Status");
int? option = int.tryParse(stdin.readLineSync() ?? '0');
if (option == 1) {
print("Please enter the new title: ");
String? t = stdin.readLineSync();
task.title = t;
print("Title of task updated successfully.");
print("\n*********************************************");
} else if (option == 2) {
print("Please enter the new description: ");
String? d = stdin.readLineSync();
task.description = d;
print("Description of task updated successfully.");
print("\n*********************************************");
} else if (option == 3) {
print("Please enter the new status: ");
String? c = stdin.readLineSync();
if (c == 'True' || c == 'true' || c == 'T' || c == 't') {
task.isCompleted = true;
print("Status of task updated successfully.");
print("\n*********************************************");
} else if (c == 'False' || c == 'false' || c == 'F' || c == 'f') {
task.isCompleted = false;
print("Status of task updated successfully.");
print("\n*********************************************");
} else {
print("Please enter a correct status.");
print("\n*********************************************");
}
} else {
print("Please enter a valid option to update.");
print("\n*********************************************");
}
} else if (i == tasks.length - 1) {
print("ID not present.");
print("\n*********************************************");
}
}
} else {
print("No Task to update");
print("\n*********************************************");
}
}
}
58 changes: 58 additions & 0 deletions src/task_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'task.dart';
import 'dart:io';

/*Implement a menu-driven interface that allows users to
add, view, update, and delete tasks using the Task class.*/
void main() {
TaskManager manager = new TaskManager();
do {
print("\n*********Welcome to Task Management System*********\n");
stdout.write(
'Please choose an option from the menu:\n1)Add Task\n2)View Task\n3)Delete Task\n4)Update Task\n0)To Exit\n');

int? option = int.tryParse(stdin.readLineSync() ?? '0');

if (option == 1) {
print("\n****************Add Task****************\n");
stdout.write("Please enter Task name: ");
String? name = stdin.readLineSync();

stdout.write("Please enter Task description: ");
String? description = stdin.readLineSync();

stdout.write("Is the task completed? (True/False): ");
String? status = stdin.readLineSync();

if (status == 'True' ||
status == 'true' ||
status == 'T' ||
status == 't') {
manager.addTask(name, description, true);
} else if (status == 'False' ||
status == 'false' ||
status == 'F' ||
status == 'f') {
manager.addTask(name, description, false);
} else {
print("Please enter a valid status");
print("\n****************************************");
}
} else if (option == 2) {
manager.display();
} else if (option == 3) {
print("\nPlease enter the ID of the task you wish to delete: ");
int? id = int.tryParse(stdin.readLineSync() ?? '0');
manager.delete(id);
} else if (option == 4) {
print("\nPlease enter the ID of the task you want to update:");
int? id = int.tryParse(stdin.readLineSync() ?? '0');
if (id == null) {
print("\nPlease enter a number.");
} else {
manager.update(id);
}
} else {
exit(0);
}
} while (true);
}
39 changes: 39 additions & 0 deletions src/variables.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//import 'task.dart';
import 'dart:io';

void main() {
//declare and initialize variables

int number = 50;
String name = "Talyia";
bool isSmart = true;
List<String> colors = ["Red", "Blue", "Pink", "Purple"];
List<Map<int, String>> id_name = [
{1: "Talyia"},
{2: "Ryam"}
];

print('Number: $number');
print('Name: $name');
print('Smart?: $isSmart');
print('Color: $colors');
print('Id with name: $id_name');

//Error Handling

try {
int result = 10 ~/ 0;
print('Result: $result');
} catch (e) {
print("An error occurred: $e");
}

//take input from user
stdout.write('Enter your name: ');
String? name2 = stdin.readLineSync();
print('Hello $name2!');
//take input from user as int
stdout.write('Enter your age: ');
int? age = int.tryParse(stdin.readLineSync()!) ?? 0;
print('Age: $age');
}