diff --git a/assets/images/sketchbook-school-backpack-with-school-supplies-1.png b/assets/images/sketchbook-school-backpack-with-school-supplies-1.png new file mode 100644 index 0000000..c3e1cd6 Binary files /dev/null and b/assets/images/sketchbook-school-backpack-with-school-supplies-1.png differ diff --git a/lib/constants/tools.dart b/lib/constants/tools.dart index c84deb7..7794cf6 100644 --- a/lib/constants/tools.dart +++ b/lib/constants/tools.dart @@ -2,17 +2,6 @@ import 'package:get/get.dart'; import 'package:academia/exports/barrel.dart'; final List> allTools = [ - { - "id": 8, - "name": "Exam Timetable", - "action": "Show exam timetable", - "image": "assets/images/sketchbook-man-analyzing-business-data.png", - "ontap": () { - Get.to(const ExamTimeTablePage()); - }, - "description": - "Exams around the corner? Don't panic we've got you covered with the timetable", - }, { "id": 1, "name": "GPA Calculator", @@ -34,9 +23,8 @@ final List> allTools = [ }, "description": "Having trouble tracking your finaces? We're here for you" }, - { - "id": 2, + "id": 3, "name": "Elearning", "image": "assets/images/sketchbook-coworkers-discussing-something-1.png", "action": "Visit Elearning", @@ -55,56 +43,19 @@ final List> allTools = [ "description": "Psst! Elearning is here for you. Keep track of your assignments and notes!", }, - // { - // "id": 5, - // "name": "Student Audit", - // "action": "Get my audit", - // "image": "assets/images/view.png", - // "ontap": () async { - // var controller = Get.find(); - // if ((controller.settings.value!.enableAudit ?? false)) { - // showCustomSnackbar( - // "Tool locked", - // "Student Audit functionality is locked in the settings page, please unlock it to view your student audit", - // icon: Icons.lock, - // ); - // } else { - // final UserController userController = Get.find(); - // Get.to(PdfViewer( - // title: "Your audit", - // url: - // "https://student.daystar.ac.ke/Downloads/STDAUDIT-${userController.user.value!.regno}.pdf", - // )); - // } - // }, - // "description": "Having trouble finding your audit? Here it is" - // }, - // { - // "id": 6, - // "name": "Transcript", - // "action": "Get my transcript", - // "image": "assets/images/graduating.png", - // "ontap": () async { - // var controller = Get.find(); - // if (controller.settings.value!.enableTranscript ?? false) { - // showCustomSnackbar( - // "Tool locked", - // "Transcript functionality is locked in the settings page, please unlock it to view your transcript", - // icon: Icons.lock, - // ); - // } else { - // final UserController userController = Get.find(); - // Get.to(PdfViewer( - // title: "Your Transcript", - // url: - // "https://student.daystar.ac.ke/Downloads/PROVISIONAL%20RESULTS-${userController.user.value!.regno}.pdf", - // )); - // } - // }, - // "description": "Need your transcript ASAP? Find it here" - // }, { - "id": 9, + "id": 4, + "name": "Exam Timetable", + "action": "Show exam timetable", + "image": "assets/images/sketchbook-man-analyzing-business-data.png", + "ontap": () { + Get.to(const ExamTimeTablePage()); + }, + "description": + "Exams around the corner? Don't panic we've got you covered with the timetable", + }, + { + "id": 5, "name": "Task Manager", "action": "Manage your tasks", "image": "assets/images/organize.png", @@ -115,7 +66,7 @@ final List> allTools = [ "Having trouble keeping track of your todos? We've got you covered", }, { - "id": 10, + "id": 6, "name": "Anki Flash Cards", "action": "Lets Up That Grade", "image": @@ -127,7 +78,7 @@ final List> allTools = [ "Ready to revolutionize your study habits?\nLet's help you master courses effortlessly", }, { - "id": 11, + "id": 7, "name": "Ask Me", "action": "Study with Ai", "image": @@ -137,5 +88,36 @@ final List> allTools = [ }, "description": "Generate quiz questions from your notes and study materials with our AI tool." + }, + { + "id": 8, + "name": "Student Audit", + "action": "Get student Audit", + "image": + "assets/images/sketchbook-school-backpack-with-school-supplies-1.png", + "ontap": () { + Get.to( + const StudentPerformancePage( + parameter: StudentPerfomanceParameter.audit, + ), + ); + }, + "description": "Need your student audit? Get it here" + }, + { + "id": 9, + "name": "Transcript", + "action": "Show my transcript", + "image": + "assets/images/sketchbook-young-businesswoman-giving-a-presentation-1.png", + "ontap": () { + Get.to( + const StudentPerformancePage( + parameter: StudentPerfomanceParameter.transcript, + ), + ); + }, + "description": + "Worried of your entire student progression? Fetch your transcript here" } ]; diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index d9d3d19..9efdce3 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -161,8 +161,9 @@ class _SettingsPageState extends State { trailing: Switch( value: settingsController.settings.value.showAudit, onChanged: (value) { - settingsController.settings - .update((val) => val?.copyWith(showAudit: value)); + settingsController.settings.value = settingsController + .settings.value + .copyWith(showAudit: value); }, ), ), @@ -177,8 +178,9 @@ class _SettingsPageState extends State { value: settingsController.settings.value.showExamTimetable, onChanged: (value) { - settingsController.settings.update( - (val) => val?.copyWith(showExamTimetable: value)); + settingsController.settings.value = settingsController + .settings.value + .copyWith(showExamTimetable: value); }, ), ), diff --git a/lib/tools/student_performance/pages/student_performance_page.dart b/lib/tools/student_performance/pages/student_performance_page.dart new file mode 100644 index 0000000..eec114f --- /dev/null +++ b/lib/tools/student_performance/pages/student_performance_page.dart @@ -0,0 +1,136 @@ +import 'package:academia/exports/barrel.dart'; +import 'package:get/get.dart'; +import 'package:http/http.dart' as http; + +enum StudentPerfomanceParameter { audit, transcript } + +class StudentPerformancePage extends StatefulWidget { + const StudentPerformancePage({ + super.key, + required this.parameter, + }); + final StudentPerfomanceParameter parameter; + + @override + State createState() => _StudentPerformancePageState(); +} + +class _StudentPerformancePageState extends State { + final SettingsController _settingsController = Get.find(); + final UserController _userController = Get.find(); + bool documentLocked = true; + int currentPage = 0, totalPages = 0; + bool isReady = false; + String errorMessage = ''; + + Future _loadPdf() async { + try { + setState(() { + isReady = false; + }); + final response = await http.get(Uri.parse(widget.parameter == + StudentPerfomanceParameter.transcript + ? "https://student.daystar.ac.ke/Downloads/STDAUDIT-${_userController.user.value!.admissionNumber}.pdf" + : "https://student.daystar.ac.ke/Downloads/PROVISIONAL%20RESULTS-${_userController.user.value!.admissionNumber}.pdf")); + if (response.statusCode != 200) { + throw "Error while fetching content"; + } + + setState(() { + isReady = true; + }); + return response.bodyBytes; + } catch (e) { + setState(() { + errorMessage = e.toString(); + }); + } + return Uint8List(0); + } + + @override + void initState() { + super.initState(); + + if (_settingsController.settings.value.showAudit && + widget.parameter == StudentPerfomanceParameter.audit) { + documentLocked = false; + return; + } + + if (_settingsController.settings.value.showTranscript && + widget.parameter == StudentPerfomanceParameter.transcript) { + documentLocked = false; + return; + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text( + widget.parameter == StudentPerfomanceParameter.audit + ? "Student Audit" + : "Student Transcript", + ), + ), + body: documentLocked + ? Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "The requested document cannot be loaded because the document is locked from the settings page", + style: Theme.of(context).textTheme.headlineSmall, + textAlign: TextAlign.center, + ), + ], + ) + : FutureBuilder( + future: _loadPdf(), + builder: (context, snapshot) { + return snapshot.hasData + ? snapshot.hasError + ? Center( + child: Column( + children: [ + Image.asset("assets/images/bot_sad.png"), + Text( + snapshot.error.toString(), + ), + ], + ), + ) + : Stack( + children: [ + PDFView( + fitPolicy: FitPolicy.BOTH, + pdfData: snapshot.data, + pageFling: true, + defaultPage: currentPage, + onPageChanged: (page, total) { + setState(() { + currentPage = page!; + }); + }, + onRender: (pages) { + setState(() {}); + }, + onError: (error) { + debugPrint("Error"); + }, + ), + ], + ) + : const Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("Loading .."), + ], + ), + ); + }), + ); + } +} diff --git a/lib/tools/student_performance/student_performance.dart b/lib/tools/student_performance/student_performance.dart new file mode 100644 index 0000000..945d87e --- /dev/null +++ b/lib/tools/student_performance/student_performance.dart @@ -0,0 +1 @@ +export 'pages/student_performance_page.dart'; diff --git a/lib/tools/tools.dart b/lib/tools/tools.dart index 0c9f384..4332b99 100644 --- a/lib/tools/tools.dart +++ b/lib/tools/tools.dart @@ -1,6 +1,6 @@ export 'leaderboard/leaderboard.dart'; export 'anki/anki.dart'; -// export 'stories/stories.dart'; +export 'student_performance/student_performance.dart'; export 'events/events.dart'; export 'fees/fees.dart'; export 'gpa_calculator/gpacalculator.dart';