Skip to content

Commit

Permalink
Merge pull request #31 from IamMuuo/dev
Browse files Browse the repository at this point in the history
Attendance
  • Loading branch information
IamMuuo authored Nov 9, 2023
2 parents ee42639 + 0161f26 commit 37f2cf7
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 56 deletions.
36 changes: 36 additions & 0 deletions lib/controllers/courses_page_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:academia/models/courses.dart';
import 'package:academia/widgets/course_attendance_widget.dart';
import 'package:academia/widgets/course_card.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand All @@ -8,6 +9,7 @@ import 'package:intl/intl.dart';
class CoursesPageController extends GetxController {
var userCourses = <Courses>[];
var hasCourses = true.obs;
var hasProgress = true.obs;

Future<bool> updateCourses() async {
var courses = await magnet.fetchTimeTable();
Expand All @@ -22,6 +24,8 @@ class CoursesPageController extends GetxController {
}
await appDB.put("timetable", userCourses);
hasCourses.value = true;

await updateProgress();
return true;
}

Expand Down Expand Up @@ -81,6 +85,30 @@ class CoursesPageController extends GetxController {
return userCourses;
}

List<Widget> buildProgressCards() {
var progress = appDB.get("attendance") ?? [];

if (progress == []) {
hasProgress.value = false;
return [];
}

var progressList = <Widget>[];

for (Map p in progress) {
progressList.add(CourseAttendanceCard(
course: p.keys.first,
percent: double.parse(p.values.first.toString()),));
}
return progressList;
}

Future<bool> updateProgress() async {
var courseProgress = await magnet.fetchUserClassAttendance();
await appDB.put("attendance", courseProgress);
return true;
}

@override
void onInit() async {
if (!appDB.containsKey("timetable")) {
Expand All @@ -90,6 +118,14 @@ class CoursesPageController extends GetxController {
hasCourses.value = true;
}
}

if (!appDB.containsKey("attendance")) {
hasProgress.value = false;
var updatedProgress = await updateProgress();
if (updatedProgress) {
hasProgress.value = true;
}
}
super.onInit();
}
}
61 changes: 61 additions & 0 deletions lib/pages/attendance_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:academia/controllers/courses_page_controller.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

class AttendancePage extends StatefulWidget {
const AttendancePage({super.key});

@override
State<AttendancePage> createState() => _AttendancePageState();
}

class _AttendancePageState extends State<AttendancePage> {
bool isLoading = false;
late CoursesPageController controller;

@override
void initState() {
controller = Get.find<CoursesPageController>();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("My Class Attendance"),
),
body: controller.hasProgress.value
? Padding(
padding: const EdgeInsets.all(2),
child: GridView.count(
crossAxisCount: 2,
mainAxisSpacing: 2,
crossAxisSpacing: 2,
children: controller.buildProgressCards(),
),
)
: const Center(
child: Text("Seems you have no course progress"),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
setState(() {
isLoading = true;
});
await controller.updateProgress();
setState(() {
isLoading = false;
});
},
child: isLoading
? LoadingAnimationWidget.horizontalRotatingDots(
color: Colors.white, size: 20)
: const Icon(Icons.refresh),
),
);
}
}
33 changes: 15 additions & 18 deletions lib/pages/courses_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:academia/controllers/courses_page_controller.dart';
import 'package:academia/widgets/course_attendance_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -55,24 +56,20 @@ class CoursesPage extends StatelessWidget {
child: Text("My Class Attendance"),
),
),
// Obx(
// () => controller.hasTimetable.value
// ? SizedBox(
// width: MediaQuery.of(context).size.width,
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: DataTable(
// columnSpacing: 10,
// columns: controller.buildDataColumn(),
// rows: controller.buildDataRow(),
// ),
// ),
// )
// : const Center(
// child: Text(
// "No units found, please pull to refresh, if the problem persists please relaunch the app!"),
// ),
// )
Obx(
() => SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: controller.hasProgress.value

? GridView.count(
crossAxisCount: 2,
padding: const EdgeInsets.all(5),
mainAxisSpacing: 2,
crossAxisSpacing: 2,
children: controller.buildProgressCards(),
) : Image.asset("assets/images/bot_sad.png")
),
),
],
),
),
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/gpacalculator_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ class GpaCalculator extends StatelessWidget {
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (unitController.courseList.length.isEqual(0)) {
if (unitController.courseList.isEmpty) {
Get.defaultDialog(
title: "List empty",
content: const Text("Input Grades!"));
title: "List empty",
content: const Text("Input Grades!"),
);
return;
}
Get.defaultDialog(
title: "Your GPA",
Expand Down
7 changes: 5 additions & 2 deletions lib/pages/tool_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:academia/controllers/tool_page_controller.dart';
import 'package:academia/pages/attendance_page.dart';
import 'package:academia/pages/gpacalculator_page.dart';
import 'package:academia/pages/webview_page.dart';
import 'package:academia/widgets/tool_card.dart';
Expand Down Expand Up @@ -41,14 +42,16 @@ class ToolsPage extends StatelessWidget {
await controller.fetchToken();
},
icon: const Icon(
Icons.check,
Icons.emoji_food_beverage,
color: Colors.white,
),
title: "Generate Token",
backGround: Colors.blueGrey,
),
ToolCard(
ontap: () {},
ontap: () {
Get.to(const AttendancePage());
},
icon: const Icon(
Icons.check,
color: Colors.white,
Expand Down
46 changes: 46 additions & 0 deletions lib/widgets/course_attendance_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:academia/constants/common.dart';
import 'package:flutter/material.dart';
import 'package:percent_indicator/percent_indicator.dart';

class CourseAttendanceCard extends StatelessWidget {
const CourseAttendanceCard({
super.key,
required this.course,
required this.percent,
});
final String course;
final double percent;

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).primaryColor,
),
),
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width * 0.38,
maxWidth: MediaQuery.of(context).size.width * 0.4,
),
child: CircularPercentIndicator(
animation: true,
animationDuration: 1000,
radius: 70,
percent: percent / 100,
lineWidth: 20,
progressColor: Theme.of(context).primaryColor,
circularStrokeCap: CircularStrokeCap.round,
center: Text(
"$percent%",
style: h6,
),
footer: Text(
course,
overflow: TextOverflow.ellipsis,
),
),
);
}
}
76 changes: 43 additions & 33 deletions lib/widgets/tool_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import 'package:academia/constants/common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

class ToolCardController extends GetxController {
var isLoading = false.obs;
}

class ToolCard extends StatelessWidget {
const ToolCard({
Expand All @@ -19,6 +26,7 @@ class ToolCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
var controller = Get.put(ToolCardController());
return Padding(
padding: const EdgeInsets.all(16),
child: Container(
Expand All @@ -29,42 +37,44 @@ class ToolCard extends StatelessWidget {
Radius.circular(12),
),
),
child: GestureDetector(
onTap: () {
ontap();
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
icon ??
const Icon(
CupertinoIcons.hammer_fill,
color: Colors.white,
),
IconButton(
onPressed: () {
ontap();
},
icon: const Icon(
CupertinoIcons.arrow_right_circle,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
icon ??
const Icon(
CupertinoIcons.hammer_fill,
color: Colors.white,
),
Obx(
() => controller.isLoading.value
? LoadingAnimationWidget.hexagonDots(
size: 20, color: Colors.white)
: IconButton(
onPressed: () async {
controller.isLoading.value = true;
ontap();
controller.isLoading.value = false;
},
icon: const Icon(
CupertinoIcons.arrow_right_circle,
color: Colors.white,
),
),
),
],
),
Text(
title,
style: titlestyle ??
h6.copyWith(
fontSize: 14,
color: Colors.white,
),
],
),
Text(
title,
style: titlestyle ??
const TextStyle(
fontSize: 20,
color: Colors.white,
),
)
],
),
)
],
),
),
);
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies:
ref: master
liquid_pull_to_refresh: ^3.0.1
cached_network_image: ^3.2.3
percent_indicator: ^4.2.3



Expand Down

0 comments on commit 37f2cf7

Please sign in to comment.