Skip to content

Commit

Permalink
Merge pull request #25 from IamMuuo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
IamMuuo authored Oct 22, 2023
2 parents f027689 + fccea72 commit 6264042
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 331 deletions.
2 changes: 1 addition & 1 deletion lib/constants/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Provides a template for the default settings

var defaultSettings = {
var settings = {
"show_profile_pic": true,
"delete_older_todos": false,
"show_gpa": true,
Expand Down
1 change: 0 additions & 1 deletion lib/controllers/courses_page_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class CoursesPageController extends GetxController {

Future<bool> updateCourses() async {
var courses = await magnet.fetchTimeTable();
debugPrint(courses.toString());

if (courses.isEmpty) {
hasCourses.value = false;
Expand Down
8 changes: 8 additions & 0 deletions lib/controllers/login_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:academia/constants/common.dart';
import 'package:academia/constants/settings.dart';
import 'package:academia/pages/home_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -52,6 +53,13 @@ class LoginController extends GetxController {

isloading.value = false;
debugPrint("User details: ${appDB.get('user')}");

// append the default settings if not exists
if(!appDB.containsKey("settings")){
await appDB.put("settings", settings);
}

// Navigate to home page
Get.off(
const HomePage(),
duration: const Duration(seconds: 2),
Expand Down
25 changes: 25 additions & 0 deletions lib/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:academia/constants/common.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SettingsController extends GetxController {
Rx<bool> showGPA = true.obs;
Rx<bool> showProfilePic = true.obs;
late Map<dynamic, dynamic> settings;

@override
void onInit() async {
settings = await appDB.get("settings");
showGPA.value = settings["show_gpa"] ?? true;
showProfilePic.value = settings["show_profile_pic"] ?? true;

debugPrint("Settings loaded!");
super.onInit();
}

Future<void> saveSettings() async {
settings["show_profile_pic"] = showProfilePic.value;
settings["show_gpa"] = showGPA.value;
await appDB.put("settings", settings);
}
}
155 changes: 7 additions & 148 deletions lib/controllers/tool_page_controller.dart
Original file line number Diff line number Diff line change
@@ -1,155 +1,14 @@
import 'package:academia/constants/common.dart';
import 'package:academia/models/schedule.dart';
import 'package:academia/widgets/task_card.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class CalendarPageController extends GetxController {
final TextEditingController taskNameController = TextEditingController();
final TextEditingController taskDescription = TextEditingController();
final TextEditingController taskTime = TextEditingController();
String? scheduleDate;

List? schedules = [].obs;
var isLoading = true.obs;

// load schedules

CalendarPageController() {
loadSchedules();
}

void printSchedules() {
for (int i = 0; i < schedules!.length; i++) {
debugPrint("Schedule ${schedules![i].taskName}");
}
}

void saveSchedule() {
appDB
.put("schedules", schedules)
.then((value) => debugPrint("Schedule saved successfully"))
.catchError((error) {
debugPrint("An error occuerred: $error");
}).whenComplete(() => Get.snackbar(
"success",
"Your schedule was saved successfully!",
icon: const Icon(
CupertinoIcons.checkmark_circle,
color: Colors.green,
),
backgroundColor: Colors.white,
));
}

void addSchedule() {
if (taskNameController.value.text.isEmpty) {
Get.snackbar(
"Error",
"You must atleast specify the name of your task before saving",
backgroundColor: Colors.white,
icon: const Icon(
CupertinoIcons.xmark_circle,
color: Colors.red,
),
);
return;
}
final Schedule s = Schedule();
s.taskName = taskNameController.text;
s.taskTime = taskTime.text;
s.taskDescription = taskDescription.text;
s.taskDate = scheduleDate;

schedules!.add(s);
schedules?.sort((a, b) => a.taskDate!.compareTo(b.taskDate!));
saveSchedule();
}

void loadSchedules() {
// dos it contain the damn key?
if (appDB.containsKey("schedules")) {
schedules = appDB.get("schedules");
} else {
schedules = <Schedule>[];
}
printSchedules();
}

List<Widget> buildTasksCards() {
if (schedules!.isNotEmpty) {
List<Widget> tasks = [];
tasks.add(
const Padding(
padding: EdgeInsets.all(8),
child: Text(
"Your saved schedules",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 25),
textAlign: TextAlign.center,
),
),
);
for (int i = 0; i < schedules!.length; i++) {
debugPrint(
"Schedule: ${schedules![i].taskName}\n ${schedules![i].taskTime}");
tasks.add(TaskCard(
taskName: schedules![i].taskName,
taskTime: schedules![i].taskTime,
taskDate: DateFormat.yMMMMEEEEd()
.format(DateTime.parse(schedules![i].taskDate)),
ondelete: () {
isLoading.value = true;
schedules!.remove(schedules![i]);
saveSchedule();
buildTasksCards();
},
));
}
isLoading.value = false;
return tasks;
}
isLoading.value = false;
return <Widget>[
Padding(
padding: const EdgeInsets.only(top: 12),
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(16),
),
),
padding: const EdgeInsets.all(12),
child: Column(
children: [
const Text(
"Seems you have no events or tasks for today",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
ClipRRect(
child: Image.asset(
"assets/images/no_task.png",
// height: 250,
// width: 250,
),
),
const Text("We will notify you once you have a task or an event"),
],
),
),
),
];
}

@override
void onInit() {
isLoading.value = false;
super.onInit();
class ToolPageController extends GetxController {
Future<void> fetchToken() async {
var token = await magnet.fetchCateringToken();
await Get.defaultDialog(
title: "Your Token",
content: Text("Your Token is ${token['message'] ?? ''}"),
);
}
}
5 changes: 1 addition & 4 deletions lib/pages/courses_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class CoursesPage extends StatelessWidget {
body: LiquidPullToRefresh(
height: 200,
onRefresh: () async {
var isUpdated = await controller.updateCourses();
if (isUpdated) {
Get.snackbar("Done!", "Courses Updated Successfully");
}
await controller.updateCourses();
},
child: ListView(
children: [
Expand Down
83 changes: 49 additions & 34 deletions lib/pages/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:academia/constants/common.dart';
import 'package:academia/controllers/profile_page_controller.dart';
import 'package:academia/controllers/settings_controller.dart';
import 'package:academia/pages/settings_page.dart';
import 'package:academia/widgets/info_card.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -21,6 +22,7 @@ class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
var controller = Get.put(ProfilePageController());
var settingsController = Get.put(SettingsController());
// controller.currentUser.value.gpa = 0.1;
controller.currentUser.value.name = "Erick";
return Scaffold(
Expand Down Expand Up @@ -57,40 +59,48 @@ class _ProfilePageState extends State<ProfilePage> {
// profile pic
Align(
alignment: Alignment.center,
child: Stack(
children: [
CircleAvatar(
radius: 60.0,
child: ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(50),
),
child: Image.memory(
Uint8List.fromList(
base64Decode(controller.currentUser.value.profile!
.replaceFirst("data:image/gif;base64,", "")),
child: Obx(
() => Stack(
children: [
CircleAvatar(
radius: 60.0,
child: ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(50),
),
child: settingsController.showProfilePic.value
? Image.memory(
Uint8List.fromList(
base64Decode(controller
.currentUser.value.profile!
.replaceFirst(
"data:image/gif;base64,", "")),
),
)
: Image.asset(user.gender == "male"
? "assets/images/male_student.png"
: "assets/images/female_student.png"),
),
),
),
if (controller.currentUser.value.gpa! > 3.0)
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: const EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
shape: BoxShape.circle,
),
child: const Icon(
CupertinoIcons.checkmark_seal_fill,
color: Colors.white,
size: 20.0,
if (controller.currentUser.value.gpa! > 3.0)
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: const EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
shape: BoxShape.circle,
),
child: const Icon(
CupertinoIcons.checkmark_seal_fill,
color: Colors.white,
size: 20.0,
),
),
),
),
],
],
),
),
),

Expand Down Expand Up @@ -138,11 +148,16 @@ class _ProfilePageState extends State<ProfilePage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
controller.currentUser.value.gpa.toString(),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
Obx(
() => Text(
settingsController.showGPA.value
? controller.currentUser.value.gpa
.toString()
: "Hidden",
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(
Expand Down
Loading

0 comments on commit 6264042

Please sign in to comment.