Skip to content

Commit

Permalink
Merge pull request #45 from NewtonMutugi/main
Browse files Browse the repository at this point in the history
fix: Loading task manager page without tasks
  • Loading branch information
IamMuuo authored Jan 11, 2024
2 parents f3f9e0c + aeffa10 commit b957c91
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 72 deletions.
4 changes: 2 additions & 2 deletions lib/controllers/taskmanager_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class TaskManagerController extends GetxController {
var isloading = false.obs;
var tasks = [].obs;

void getTasks() {
Future<void> getTasks() async {
tasks.clear();
final tasksList = appDB.get("tasks") ?? [];
final tasksList = await appDB.get("tasks") ?? [];
for (final task in tasksList) {
tasks.add(task);
}
Expand Down
139 changes: 69 additions & 70 deletions lib/pages/tasks_pages/taskmanager_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:academia/controllers/taskmanager_controller.dart';
import 'package:academia/models/tasks.dart';
import 'package:academia/pages/tasks_pages/newtask_page.dart';
import 'package:academia/pages/tasks_pages/taskinfo_page.dart';
import 'package:flutter/material.dart';
Expand All @@ -11,78 +12,76 @@ class TaskManagerPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Obx(() {
taskManagerController.getTasks();
final tasks = taskManagerController.tasks;
taskManagerController.getTasks();
final tasks = taskManagerController.tasks;

return Scaffold(
appBar: AppBar(title: const Text("Task Manager"), actions: [
IconButton(
onPressed: () {
Get.defaultDialog(
title: "Task Manager",
content: const Text(
"This is the task manager. You can add tasks here and view them in the calendar."),
textConfirm: "Got it!",
confirmTextColor: Colors.white,
onConfirm: () => Get.back(),
);
},
icon: const Icon(Icons.info_rounded),
),
]),
body: // Check if there are any tasks
tasks.isEmpty
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.task, size: 100),
Text("No tasks yet"),
],
),
)
: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(tasks[index].title ?? ''),
subtitle: Text(tasks[index].unit ?? ''),
trailing: Column(
children: [
Text(
DateFormat("dd/MM/yyyy").format(
(tasks[index].deadline ?? DateTime.now())),
),
const SizedBox(height: 5),
Text(
"${tasks[index].progress}%",
)
],
),
onTap: () {
taskManagerController.updateTask(
tasks[index].type ?? '',
tasks[index].title ?? '',
tasks[index].description ?? '',
tasks[index].unit ?? '',
tasks[index].deadline ?? DateTime.now(),
tasks[index].progress ?? 0);
Get.to(() => TaskInformationPage(
task: tasks[index],
));
},
));
},
),
floatingActionButton: FloatingActionButton(
return Obx(() => Scaffold(
appBar: AppBar(title: const Text("Task Manager"), actions: [
IconButton(
onPressed: () {
taskManagerController.clearTaskManager();
Get.to(() => NewTaskPage());
Get.defaultDialog(
title: "Task Manager",
content: const Text(
"This is the task manager. You can add tasks here and view them in the calendar."),
textConfirm: "Got it!",
confirmTextColor: Colors.white,
onConfirm: () => Get.back(),
);
},
child: const Icon(Icons.add),
));
});
icon: const Icon(Icons.info_rounded),
),
]),
body: // Check if there are any tasks
tasks.isEmpty
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.task, size: 100),
Text("No tasks yet"),
],
),
)
: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(tasks[index].title ?? ''),
subtitle: Text(tasks[index].unit ?? ''),
trailing: Column(
children: [
Text(
DateFormat("dd/MM/yyyy").format(
(tasks[index].deadline ?? DateTime.now())),
),
const SizedBox(height: 5),
Text(
"${tasks[index].progress}%",
)
],
),
onTap: () {
taskManagerController.updateTask(
tasks[index].type ?? '',
tasks[index].title ?? '',
tasks[index].description ?? '',
tasks[index].unit ?? '',
tasks[index].deadline ?? DateTime.now(),
tasks[index].progress ?? 0);
Get.to(() => TaskInformationPage(
task: tasks[index],
));
},
));
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
taskManagerController.clearTaskManager();
Get.to(() => NewTaskPage());
},
child: const Icon(Icons.add),
)));
}
}

0 comments on commit b957c91

Please sign in to comment.