11import 'package:flutter/material.dart' ;
2+ import 'package:mujslcm/session_manager.dart' ;
23import 'redirects.dart' ;
3- import 'dart:convert' ;
4- import 'package:http/http.dart' as http;
54import 'package:fl_chart/fl_chart.dart' ;
5+ import 'package:mujslcm/utils/util.dart' ;
66
77class AttendancePage extends StatefulWidget {
8- final String newCookies;
9-
10- const AttendancePage ({Key ? key, required this .newCookies}) : super (key: key);
8+ const AttendancePage ({super .key});
119
1210 @override
1311 _AttendancePageState createState () => _AttendancePageState ();
@@ -19,30 +17,27 @@ class _AttendancePageState extends State<AttendancePage> {
1917 @override
2018 void initState () {
2119 super .initState ();
22- _attendanceData = fetchAttendance (widget.newCookies );
20+ _attendanceData = fetchAttendance (SessionManager .sessionCookie ?? "" );
2321 }
2422
2523 Future <List <Map <String , dynamic >>?> fetchAttendance (String newCookies) async {
26- final Map <String , String > headers = {
27- "User-Agent" :
28- "Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0" ,
24+ final Map <String , String > header = {
25+ ...headers,
2926 "Cookie" : newCookies,
3027 };
3128
3229 final Map <String , String > body = {"StudentCode" : "" };
3330
3431 final attendanceUrl = Attendance ;
3532
36- final session = http.Client ();
37- final response = await session.post (Uri .parse (attendanceUrl),
38- headers: headers, body: body);
33+ final response = await post (attendanceUrl, header, body);
3934
4035 if (response.statusCode != 200 ) {
4136 print ('Failed to load attendance data' );
4237 return null ;
4338 }
4439
45- final decoded = jsonDecode ( response.body) ;
40+ final decoded = response.data ;
4641 final List <dynamic > attendanceList = decoded["AttendanceSummaryList" ];
4742
4843 List <Map <String , dynamic >> attendanceData = [];
@@ -68,7 +63,7 @@ class _AttendancePageState extends State<AttendancePage> {
6863 int ? classesNeeded;
6964 if (newpercentage < 75 ) {
7065 classesNeeded =
71- ((0.75 * totalClasses - attendedClasses) / (1 - 0.75 )).ceil ();
66+ ((0.75 * totalClasses - attendedClasses) / (1 - 0.75 )).floor ();
7267 statusMessage = "$classesNeeded more classes needed to reach 75%." ;
7368 } else {
7469 statusMessage = "Good! Your attendance is above or equal to 75%." ;
@@ -87,7 +82,6 @@ class _AttendancePageState extends State<AttendancePage> {
8782 });
8883 }
8984
90- session.close ();
9185 return attendanceData;
9286 }
9387
@@ -113,7 +107,7 @@ class _AttendancePageState extends State<AttendancePage> {
113107 child: Container (
114108 width: double .infinity,
115109 height: double .infinity,
116- decoration: BoxDecoration (
110+ decoration: const BoxDecoration (
117111 color: Color (0xFF212121 ),
118112 borderRadius: const BorderRadius .only (
119113 topLeft: Radius .circular (40 ),
0 commit comments