From f39523d83141d4abd8c60e515b7acdb821e357c4 Mon Sep 17 00:00:00 2001 From: Atharva Date: Sat, 20 Jul 2024 15:35:18 +0530 Subject: [PATCH 1/4] fixed null on attendence page and added floating actionbutton --- .../attendance_screen/attendance_screen.dart | 352 +++++++++--------- 1 file changed, 184 insertions(+), 168 deletions(-) diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index 4a01d70..43add23 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -18,184 +18,200 @@ class AttendanceScreen extends StatelessWidget { //put the attendance from a provider here double attendance = present / totalLec; var size = MediaQuery.of(context).size; - return SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - // const SizedBox(height: 20,), - // Text( - // attendance < 0.75 ? 'Your attendance is low' : 'Your attendance is good', - // style: TextStyle(color: Colors.white, fontSize: 20), - // ), - const SizedBox( - height: 30, - ), - Stack( - children: [ - Positioned.fill( - child: Align( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - '', - style: TextStyle(color: Colors.white, fontSize: 4), - ), - Text( - '${attendance * 100}%', - style: TextStyle(color: Colors.white, fontSize: 17), - ), - Text( - '${present}/${totalLec}', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - ], + return Scaffold( + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + children: [ + // const SizedBox(height: 20,), + // Text( + // attendance < 0.75 ? 'Your attendance is low' : 'Your attendance is good', + // style: TextStyle(color: Colors.white, fontSize: 20), + // ), + const SizedBox( + height: 30, + ), + Stack( + children: [ + Positioned.fill( + child: Align( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + '', + style: TextStyle(color: Colors.white, fontSize: 4), + ), + Text( + '${attendance * 100}%', + style: TextStyle(color: Colors.white, fontSize: 17), + ), + Text( + '${present}/${totalLec}', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ], + ), ), ), - ), - SizedBox( - width: 100, - height: 100, - child: CircularProgressIndicator( - value: attendance, - backgroundColor: Colors.white, - valueColor: - AlwaysStoppedAnimation(oldDateSelectBlue), - strokeWidth: 3, - strokeAlign: BorderSide.strokeAlignInside, - strokeCap: StrokeCap.butt, + SizedBox( + width: 100, + height: 100, + child: CircularProgressIndicator( + value: attendance, + backgroundColor: Colors.white, + valueColor: + AlwaysStoppedAnimation(oldDateSelectBlue), + strokeWidth: 3, + strokeAlign: BorderSide.strokeAlignInside, + strokeCap: StrokeCap.butt, + ), ), - ), - ], - ), - const SizedBox( - height: 20, - ), - //put the subject attendance cards from here - const SizedBox( - height: 10, - ), - StreamBuilder( - stream: FirebaseFirestore.instance - .collection("Attendance") - .doc(auth.currentUser!.uid) - .snapshots(), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return CircularProgressIndicator(); - } - var documentSnapshot = snapshot.data as DocumentSnapshot; - var data = documentSnapshot.data() as Map; - List attendanceList = data['attendance']; - return ListView.builder( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - itemCount: attendanceList.length, - itemBuilder: (context, index) { - var attendanceInfo = attendanceList[index]; - return Card( - child: Container( - decoration: BoxDecoration( - border: Border.all(color: timePickerBorder, width: 1.0), // Change the color and width as needed - borderRadius: BorderRadius.circular(10.0), - color: timePickerBg, - ), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - //crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text( - attendanceInfo["subject_name"], - style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold), - ), - SizedBox(width: 5,), - ], - ), - const SizedBox(height: 10,), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - '${attendanceInfo['present']}/${attendanceInfo['total']}', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - Text( - '${(attendanceInfo['present']/attendanceInfo['total'] *100).toInt()}%', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - ], - ), - const SizedBox(height: 10,), - LinearProgressIndicator( - value: attendanceInfo['present']/attendanceInfo['total'], - backgroundColor: Colors.white, - valueColor: const AlwaysStoppedAnimation(Colors.blue), - ), - const SizedBox(height: 15,), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - onPressed: (){ - AttendanceService.markPresent(attendanceList, index); - }, - child: const Text('Present', style: TextStyle(color: Colors.white),), - style: ElevatedButton.styleFrom( - backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + ], + ), + const SizedBox( + height: 20, + ), + //put the subject attendance cards from here + const SizedBox( + height: 10, + ), + StreamBuilder( + stream: FirebaseFirestore.instance + .collection("Attendance") + .doc(auth.currentUser!.uid) + .snapshots(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center(child: CircularProgressIndicator()); + } + var documentSnapshot = snapshot.data as DocumentSnapshot; + // print("lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"); + if(documentSnapshot.data()==null){ + return Center(child: Text("Please add Subject",style: TextStyle(color: Colors.white),)); + } + var data = documentSnapshot.data() as Map; + List attendanceList = data['attendance']; + return ListView.builder( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemCount: attendanceList.length, + itemBuilder: (context, index) { + var attendanceInfo = attendanceList[index]; + return Card( + child: Container( + decoration: BoxDecoration( + border: Border.all(color: timePickerBorder, width: 1.0), // Change the color and width as needed + borderRadius: BorderRadius.circular(10.0), + color: timePickerBg, + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + //crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + attendanceInfo["subject_name"], + style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold), ), - ), - ElevatedButton( - onPressed: (){}, - child: Transform( - alignment: Alignment.center, - transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally - child: Icon(Icons.refresh_outlined, color: Colors.white), - ) - , - style: ElevatedButton.styleFrom( - backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + SizedBox(width: 5,), + ], + ), + const SizedBox(height: 10,), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '${attendanceInfo['present']}/${attendanceInfo['total']}', + style: TextStyle(color: Colors.white, fontSize: 14), ), - ), - ElevatedButton( - onPressed: (){ - AttendanceService.markAbsent(attendanceList, index); - }, - child: const Text('Absent', style: TextStyle(color: Colors.white),), - style: ElevatedButton.styleFrom( - backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + Text( + '${(attendanceInfo['present']/attendanceInfo['total'] *100).toInt()}%', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ], + ), + const SizedBox(height: 10,), + LinearProgressIndicator( + value: attendanceInfo['present']/attendanceInfo['total'], + backgroundColor: Colors.white, + valueColor: const AlwaysStoppedAnimation(Colors.blue), + ), + const SizedBox(height: 15,), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ElevatedButton( + onPressed: (){ + AttendanceService.markPresent(attendanceList, index); + }, + child: const Text('Present', style: TextStyle(color: Colors.white),), + style: ElevatedButton.styleFrom( + backgroundColor: commonbgL3ightblack, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + ), + ), + ElevatedButton( + onPressed: (){}, + child: Transform( + alignment: Alignment.center, + transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally + child: Icon(Icons.refresh_outlined, color: Colors.white), + ) + , + style: ElevatedButton.styleFrom( + backgroundColor: commonbgL3ightblack, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + ), + ), + ElevatedButton( + onPressed: (){ + AttendanceService.markAbsent(attendanceList, index); + }, + child: const Text('Absent', style: TextStyle(color: Colors.white),), + style: ElevatedButton.styleFrom( + backgroundColor: commonbgL3ightblack, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + ), ), - ), - ], - ), - const SizedBox(height: 10,), - Center( - child: Container( - height: 1, - width: size.width*0.88, - color: commonbgL4ightblack, + ], ), - ), - const SizedBox(height: 10,), - ], + const SizedBox(height: 10,), + Center( + child: Container( + height: 1, + width: size.width*0.88, + color: commonbgL4ightblack, + ), + ), + const SizedBox(height: 10,), + ], + ), ), - ), - ) - ); - }, - ); - }), - ], + ) + ); + }, + ); + }), + ], + ), + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: (){ + + }, + shape: CircleBorder( + side: BorderSide(color: commonbgL4ightblack, width: 0.5), // Customize the border color and width ), + backgroundColor: commonbgLightblack, + child: Icon(Icons.add,color: Colors.blue,), ), ); } From cbf1c8d54519c726c9a895716d54d97fe81abd65 Mon Sep 17 00:00:00 2001 From: Atharva Date: Sat, 20 Jul 2024 16:15:10 +0530 Subject: [PATCH 2/4] added manhy things in attendence --- .../attendance_screen/attendance_screen.dart | 384 +++++++++++++++++- .../widgets/attendanceservice.dart | 1 + .../guidelines_screen/guidelinesscreen.dart | 3 + 3 files changed, 372 insertions(+), 16 deletions(-) diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index 43add23..e1eec05 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -94,16 +94,268 @@ class AttendanceScreen extends StatelessWidget { } var data = documentSnapshot.data() as Map; List attendanceList = data['attendance']; + // return ListView.builder( + // shrinkWrap: true, + // physics: NeverScrollableScrollPhysics(), + // itemCount: attendanceList.length, + // itemBuilder: (context, index) { + // var attendanceInfo = attendanceList[index]; + // return Card( + // child: Container( + // decoration: BoxDecoration( + // border: Border.all(color: timePickerBorder, width: 1.0), // Change the color and width as needed + // borderRadius: BorderRadius.circular(10.0), + // color: timePickerBg, + // ), + // child: Padding( + // padding: const EdgeInsets.all(8.0), + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Row( + // //crossAxisAlignment: CrossAxisAlignment.end, + // children: [ + // Text( + // attendanceInfo["subject_name"], + // style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold), + // ), + // SizedBox(width: 5,), + // ], + // ), + // const SizedBox(height: 10,), + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // children: [ + // Text( + // '${attendanceInfo['present']}/${attendanceInfo['total']}', + // style: TextStyle(color: Colors.white, fontSize: 14), + // ), + // Text( + // '${(attendanceInfo['present']/attendanceInfo['total'] *100).toInt()}%', + // style: TextStyle(color: Colors.white, fontSize: 14), + // ), + // ], + // ), + // const SizedBox(height: 10,), + // LinearProgressIndicator( + // value: attendanceInfo['present']/attendanceInfo['total'], + // backgroundColor: Colors.white, + // valueColor: const AlwaysStoppedAnimation(Colors.blue), + // ), + // const SizedBox(height: 15,), + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // children: [ + // ElevatedButton( + // onPressed: (){ + // AttendanceService.markPresent(attendanceList, index); + // }, + // child: const Text('Present', style: TextStyle(color: Colors.white),), + // style: ElevatedButton.styleFrom( + // backgroundColor: commonbgL3ightblack, + // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + // ), + // ), + // ElevatedButton( + // onPressed: (){}, + // child: Transform( + // alignment: Alignment.center, + // transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally + // child: Icon(Icons.refresh_outlined, color: Colors.white), + // ) + // , + // style: ElevatedButton.styleFrom( + // backgroundColor: commonbgL3ightblack, + // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + // ), + // ), + // ElevatedButton( + // onPressed: (){ + // AttendanceService.markAbsent(attendanceList, index); + // }, + // child: const Text('Absent', style: TextStyle(color: Colors.white),), + // style: ElevatedButton.styleFrom( + // backgroundColor: commonbgL3ightblack, + // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + // ), + // ), + // + // ], + // ), + // const SizedBox(height: 10,), + // Center( + // child: Container( + // height: 1, + // width: size.width*0.88, + // color: commonbgL4ightblack, + // ), + // ), + // const SizedBox(height: 10,), + // ], + // ), + // ), + // ) + // ); + // }, + // ); return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: attendanceList.length, itemBuilder: (context, index) { var attendanceInfo = attendanceList[index]; - return Card( + + return GestureDetector( + onTap: () { + // Show dialog with current values for modification + showDialog( + context: context, + builder: (BuildContext context) { + TextEditingController subjectNameController = TextEditingController(text: attendanceInfo["subject_name"]); + TextEditingController totalLecturesController = TextEditingController(text: attendanceInfo["total"].toString()); + TextEditingController attendedLecturesController = TextEditingController(text: attendanceInfo["present"].toString()); + + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15), + ), + title: Text('Update Subject'), + content: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: subjectNameController, + style: TextStyle(color: Colors.white), + decoration: InputDecoration( + labelText: 'Subject Name', + labelStyle: TextStyle(color: Colors.white70), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + ), + SizedBox(height: 10), + TextField( + controller: attendedLecturesController, + style: TextStyle(color: Colors.white), + decoration: InputDecoration( + labelText: 'Attended Lectures', + labelStyle: TextStyle(color: Colors.white70), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + keyboardType: TextInputType.number, + ), + SizedBox(height: 10), + TextField( + controller: totalLecturesController, + style: TextStyle(color: Colors.white), + decoration: InputDecoration( + labelText: 'Total Lectures Till Now', + labelStyle: TextStyle(color: Colors.white70), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + keyboardType: TextInputType.number, + ), + + ], + ), + ), + actions: [ + TextButton( + onPressed: () async { + String subjectName = subjectNameController.text; + int totalLectures = int.parse(totalLecturesController.text); + int attendedLectures = int.parse(attendedLecturesController.text); + + // Fetch the document to get the current data + DocumentSnapshot doc = await FirebaseFirestore.instance + .collection("Attendance") + .doc(FirebaseAuth.instance.currentUser!.uid) + .get(); + + if (doc.exists) { + var data = doc.data() as Map; + List attendanceList = data['attendance']; + + // Find the index of the subject to update + int indexToUpdate = attendanceList.indexWhere((item) => item['subject_name'] == attendanceInfo['subject_name']); + + if (indexToUpdate != -1) { + // Update the specific item + attendanceList[indexToUpdate] = { + 'subject_name': subjectName, + 'total': totalLectures, + 'present': attendedLectures, + }; + + // Update the document with the modified array + await FirebaseFirestore.instance + .collection("Attendance") + .doc(FirebaseAuth.instance.currentUser!.uid) + .update({'attendance': attendanceList}); + } + } + + Navigator.of(context).pop(); + }, + child: Text('Update', style: TextStyle(color: Colors.blue)), + ), + TextButton( + onPressed: () async { + // Fetch the document to get the current data + DocumentSnapshot doc = await FirebaseFirestore.instance + .collection("Attendance") + .doc(FirebaseAuth.instance.currentUser!.uid) + .get(); + + if (doc.exists) { + var data = doc.data() as Map; + List attendanceList = data['attendance']; + + // Remove the subject to delete + attendanceList.removeWhere((item) => item['subject_name'] == attendanceInfo['subject_name']); + + // Update the document with the modified array + await FirebaseFirestore.instance + .collection("Attendance") + .doc(FirebaseAuth.instance.currentUser!.uid) + .update({'attendance': attendanceList}); + } + + Navigator.of(context).pop(); + }, + child: Text('Delete', style: TextStyle(color: Colors.red)), + ), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('Cancel', style: TextStyle(color: Colors.grey)), + ), + + ], + ); + }, + ); + }, + child: Card( child: Container( decoration: BoxDecoration( - border: Border.all(color: timePickerBorder, width: 1.0), // Change the color and width as needed + border: Border.all(color: timePickerBorder, width: 1.0), borderRadius: BorderRadius.circular(10.0), color: timePickerBg, ), @@ -113,7 +365,6 @@ class AttendanceScreen extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - //crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( attendanceInfo["subject_name"], @@ -147,46 +398,44 @@ class AttendanceScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ ElevatedButton( - onPressed: (){ + onPressed: () { AttendanceService.markPresent(attendanceList, index); }, child: const Text('Present', style: TextStyle(color: Colors.white),), style: ElevatedButton.styleFrom( backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), ), ), ElevatedButton( - onPressed: (){}, + onPressed: () {}, child: Transform( alignment: Alignment.center, transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally child: Icon(Icons.refresh_outlined, color: Colors.white), - ) - , + ), style: ElevatedButton.styleFrom( backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), ), ), ElevatedButton( - onPressed: (){ + onPressed: () { AttendanceService.markAbsent(attendanceList, index); }, child: const Text('Absent', style: TextStyle(color: Colors.white),), style: ElevatedButton.styleFrom( backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), ), ), - ], ), const SizedBox(height: 10,), Center( child: Container( height: 1, - width: size.width*0.88, + width: size.width * 0.88, color: commonbgL4ightblack, ), ), @@ -194,7 +443,8 @@ class AttendanceScreen extends StatelessWidget { ], ), ), - ) + ), + ), ); }, ); @@ -204,14 +454,116 @@ class AttendanceScreen extends StatelessWidget { ), ), floatingActionButton: FloatingActionButton( - onPressed: (){ + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + TextEditingController subjectNameController = TextEditingController(); + TextEditingController totalLecturesController = TextEditingController(); + TextEditingController attendedLecturesController = TextEditingController(); + + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15), // Increased corner radius + ), + title: Text( + 'Add Subject', + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18), + ), + content: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10.0), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + style: TextStyle(color: Colors.white), // Set text color to white + controller: subjectNameController, + decoration: InputDecoration( + focusColor: Colors.red, + labelText: 'Subject Name', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + ), + SizedBox(height: 10), + TextField( + style: TextStyle(color: Colors.white), // Set text color to white + controller: attendedLecturesController, + decoration: InputDecoration( + labelText: 'Attended Lectures', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + keyboardType: TextInputType.number, + ), + SizedBox(height: 10), + TextField( + style: TextStyle(color: Colors.white), // Set text color to white + controller: totalLecturesController, + decoration: InputDecoration( + labelText: 'Total Lectures Till Now', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + filled: true, + fillColor: Colors.transparent, + contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), + ), + keyboardType: TextInputType.number, + ), + + ], + ), + ), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('Cancel', style: TextStyle(color: Colors.red)), + ), + TextButton( + onPressed: () { + String subjectName = subjectNameController.text; + int totalLectures = int.parse(totalLecturesController.text); + int attendedLectures = int.parse(attendedLecturesController.text); + + // Define your action here to handle the input data + FirebaseFirestore.instance + .collection("Attendance") + .doc(FirebaseAuth.instance.currentUser!.uid) + .set({ + 'attendance': FieldValue.arrayUnion([{ + 'subject_name': subjectName, + 'total': totalLectures, + 'present': attendedLectures + }]) + }, SetOptions(merge: true)); + Navigator.of(context).pop(); + }, + child: Text('Add', style: TextStyle(color: Colors.blue)), + ), + ], + ); + }, + ); }, shape: CircleBorder( side: BorderSide(color: commonbgL4ightblack, width: 0.5), // Customize the border color and width ), backgroundColor: commonbgLightblack, - child: Icon(Icons.add,color: Colors.blue,), + child: Icon(Icons.add, color: Colors.blue), ), ); } diff --git a/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart b/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart index 876c05d..e064bf6 100644 --- a/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart +++ b/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart @@ -8,6 +8,7 @@ class AttendanceService{ static markPresent(List attendanceList,int index){ attendanceList[index]['present']++; + attendanceList[index]['total']++; print(attendanceList[index]['present']); firestore.doc(auth.currentUser!.uid).set({"attendance":attendanceList}); } diff --git a/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart b/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart index 1b4af9a..d883d0d 100644 --- a/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart +++ b/lib/new_ui/screens/guidelines_screen/guidelinesscreen.dart @@ -79,6 +79,9 @@ class _GuideLinesScreenState extends State { context: context, builder: (BuildContext context) { return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), title: Text( "FAQ", style: TextStyle(color: Colors.white,fontWeight: FontWeight.w700,fontSize: 20, From b101bd28194a93c40b55277e7d3b09bc4777995b Mon Sep 17 00:00:00 2001 From: Atharva Date: Sat, 20 Jul 2024 19:19:11 +0530 Subject: [PATCH 3/4] converted from stateless to stateful. then added text. --- lib/hallOfShame.txt | 1 + .../attendance_screen/attendance_screen.dart | 264 ++++++++---------- 2 files changed, 124 insertions(+), 141 deletions(-) create mode 100644 lib/hallOfShame.txt diff --git a/lib/hallOfShame.txt b/lib/hallOfShame.txt new file mode 100644 index 0000000..ee85c37 --- /dev/null +++ b/lib/hallOfShame.txt @@ -0,0 +1 @@ +1. \ No newline at end of file diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index e1eec05..0bf753c 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -1,3 +1,5 @@ +import 'dart:ffi'; + import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; @@ -6,17 +8,39 @@ import 'package:tsec_app/new_ui/screens/attendance_screen/widgets/attendance_sub import 'package:tsec_app/new_ui/screens/attendance_screen/widgets/attendanceservice.dart'; import 'package:tsec_app/provider/auth_provider.dart'; -//make this a consumer widget later -class AttendanceScreen extends StatelessWidget { +class AttendanceScreen extends StatefulWidget { + const AttendanceScreen({super.key}); + + @override + State createState() => _AttendanceScreenState(); +} + +class _AttendanceScreenState extends State { final FirebaseAuth auth = FirebaseAuth.instance; AttendanceService attendanceService = AttendanceService(); + int totalLectures = 0; + int attendedLectures = 0; + + @override + void initState() { + super.initState(); + _fetchAndSetAttendance(); + + } + + Future _fetchAndSetAttendance() async { + var attendanceData = await fetchAttendanceData(); + setState(() { + totalLectures = attendanceData['totalLectures']!; + attendedLectures = attendanceData['attendedLectures']!; + print("init state"); + print(totalLectures); + print(attendedLectures); + }); + } @override Widget build(BuildContext context) { - var present = 8; - var totalLec = 10; - //put the attendance from a provider here - double attendance = present / totalLec; var size = MediaQuery.of(context).size; return Scaffold( body: SingleChildScrollView( @@ -24,11 +48,6 @@ class AttendanceScreen extends StatelessWidget { padding: const EdgeInsets.all(8.0), child: Column( children: [ - // const SizedBox(height: 20,), - // Text( - // attendance < 0.75 ? 'Your attendance is low' : 'Your attendance is good', - // style: TextStyle(color: Colors.white, fontSize: 20), - // ), const SizedBox( height: 30, ), @@ -45,12 +64,12 @@ class AttendanceScreen extends StatelessWidget { style: TextStyle(color: Colors.white, fontSize: 4), ), Text( - '${attendance * 100}%', + '${((attendedLectures/totalLectures) * 100).toStringAsFixed(2)}%', style: TextStyle(color: Colors.white, fontSize: 17), ), Text( - '${present}/${totalLec}', - style: TextStyle(color: Colors.white, fontSize: 14), + '${attendedLectures}/${totalLectures}', + style: TextStyle(color: Colors.white, fontSize: 13), ), ], ), @@ -60,7 +79,7 @@ class AttendanceScreen extends StatelessWidget { width: 100, height: 100, child: CircularProgressIndicator( - value: attendance, + value: totalLectures==0?0:(attendedLectures/totalLectures), backgroundColor: Colors.white, valueColor: AlwaysStoppedAnimation(oldDateSelectBlue), @@ -88,116 +107,17 @@ class AttendanceScreen extends StatelessWidget { return Center(child: CircularProgressIndicator()); } var documentSnapshot = snapshot.data as DocumentSnapshot; - // print("lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"); - if(documentSnapshot.data()==null){ + if(documentSnapshot.data()==null ){ return Center(child: Text("Please add Subject",style: TextStyle(color: Colors.white),)); } var data = documentSnapshot.data() as Map; List attendanceList = data['attendance']; - // return ListView.builder( - // shrinkWrap: true, - // physics: NeverScrollableScrollPhysics(), - // itemCount: attendanceList.length, - // itemBuilder: (context, index) { - // var attendanceInfo = attendanceList[index]; - // return Card( - // child: Container( - // decoration: BoxDecoration( - // border: Border.all(color: timePickerBorder, width: 1.0), // Change the color and width as needed - // borderRadius: BorderRadius.circular(10.0), - // color: timePickerBg, - // ), - // child: Padding( - // padding: const EdgeInsets.all(8.0), - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // Row( - // //crossAxisAlignment: CrossAxisAlignment.end, - // children: [ - // Text( - // attendanceInfo["subject_name"], - // style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold), - // ), - // SizedBox(width: 5,), - // ], - // ), - // const SizedBox(height: 10,), - // Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // Text( - // '${attendanceInfo['present']}/${attendanceInfo['total']}', - // style: TextStyle(color: Colors.white, fontSize: 14), - // ), - // Text( - // '${(attendanceInfo['present']/attendanceInfo['total'] *100).toInt()}%', - // style: TextStyle(color: Colors.white, fontSize: 14), - // ), - // ], - // ), - // const SizedBox(height: 10,), - // LinearProgressIndicator( - // value: attendanceInfo['present']/attendanceInfo['total'], - // backgroundColor: Colors.white, - // valueColor: const AlwaysStoppedAnimation(Colors.blue), - // ), - // const SizedBox(height: 15,), - // Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - // children: [ - // ElevatedButton( - // onPressed: (){ - // AttendanceService.markPresent(attendanceList, index); - // }, - // child: const Text('Present', style: TextStyle(color: Colors.white),), - // style: ElevatedButton.styleFrom( - // backgroundColor: commonbgL3ightblack, - // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), - // ), - // ), - // ElevatedButton( - // onPressed: (){}, - // child: Transform( - // alignment: Alignment.center, - // transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally - // child: Icon(Icons.refresh_outlined, color: Colors.white), - // ) - // , - // style: ElevatedButton.styleFrom( - // backgroundColor: commonbgL3ightblack, - // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), - // ), - // ), - // ElevatedButton( - // onPressed: (){ - // AttendanceService.markAbsent(attendanceList, index); - // }, - // child: const Text('Absent', style: TextStyle(color: Colors.white),), - // style: ElevatedButton.styleFrom( - // backgroundColor: commonbgL3ightblack, - // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), - // ), - // ), - // - // ], - // ), - // const SizedBox(height: 10,), - // Center( - // child: Container( - // height: 1, - // width: size.width*0.88, - // color: commonbgL4ightblack, - // ), - // ), - // const SizedBox(height: 10,), - // ], - // ), - // ), - // ) - // ); - // }, - // ); + List> attendanceList2 = attendanceList.cast>(); + + + + + return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), @@ -238,7 +158,7 @@ class AttendanceScreen extends StatelessWidget { contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), ), ), - SizedBox(height: 10), + SizedBox(height: 20), TextField( controller: attendedLecturesController, style: TextStyle(color: Colors.white), @@ -254,7 +174,7 @@ class AttendanceScreen extends StatelessWidget { ), keyboardType: TextInputType.number, ), - SizedBox(height: 10), + SizedBox(height: 20), TextField( controller: totalLecturesController, style: TextStyle(color: Colors.white), @@ -326,10 +246,8 @@ class AttendanceScreen extends StatelessWidget { var data = doc.data() as Map; List attendanceList = data['attendance']; - // Remove the subject to delete attendanceList.removeWhere((item) => item['subject_name'] == attendanceInfo['subject_name']); - // Update the document with the modified array await FirebaseFirestore.instance .collection("Attendance") .doc(FirebaseAuth.instance.currentUser!.uid) @@ -391,7 +309,7 @@ class AttendanceScreen extends StatelessWidget { LinearProgressIndicator( value: attendanceInfo['present']/attendanceInfo['total'], backgroundColor: Colors.white, - valueColor: const AlwaysStoppedAnimation(Colors.blue), + valueColor: const AlwaysStoppedAnimation(oldDateSelectBlue), ), const SizedBox(height: 15,), Row( @@ -400,6 +318,7 @@ class AttendanceScreen extends StatelessWidget { ElevatedButton( onPressed: () { AttendanceService.markPresent(attendanceList, index); + _fetchAndSetAttendance(); }, child: const Text('Present', style: TextStyle(color: Colors.white),), style: ElevatedButton.styleFrom( @@ -407,21 +326,11 @@ class AttendanceScreen extends StatelessWidget { shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), ), ), - ElevatedButton( - onPressed: () {}, - child: Transform( - alignment: Alignment.center, - transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0), // Flip horizontally - child: Icon(Icons.refresh_outlined, color: Colors.white), - ), - style: ElevatedButton.styleFrom( - backgroundColor: commonbgL3ightblack, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), - ), - ), + ElevatedButton( onPressed: () { AttendanceService.markAbsent(attendanceList, index); + _fetchAndSetAttendance(); }, child: const Text('Absent', style: TextStyle(color: Colors.white),), style: ElevatedButton.styleFrom( @@ -434,9 +343,9 @@ class AttendanceScreen extends StatelessWidget { const SizedBox(height: 10,), Center( child: Container( - height: 1, width: size.width * 0.88, color: commonbgL4ightblack, + child: Text(getTextForCard(attendanceInfo['present'], attendanceInfo['total'])), ), ), const SizedBox(height: 10,), @@ -490,7 +399,7 @@ class AttendanceScreen extends StatelessWidget { contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10), ), ), - SizedBox(height: 10), + SizedBox(height: 20), TextField( style: TextStyle(color: Colors.white), // Set text color to white controller: attendedLecturesController, @@ -505,7 +414,7 @@ class AttendanceScreen extends StatelessWidget { ), keyboardType: TextInputType.number, ), - SizedBox(height: 10), + SizedBox(height: 20), TextField( style: TextStyle(color: Colors.white), // Set text color to white controller: totalLecturesController, @@ -568,3 +477,76 @@ class AttendanceScreen extends StatelessWidget { ); } } + +Future> fetchAttendanceData() async { + FirebaseAuth auth = FirebaseAuth.instance; + + DocumentSnapshot documentSnapshot = await FirebaseFirestore.instance + .collection("Attendance") + .doc(auth.currentUser!.uid) + .get(); + + if (documentSnapshot.exists) { + var data = documentSnapshot.data() as Map; + List attendanceList = data['attendance']; + List> attendanceList2 = attendanceList.cast>(); + + return calculateAttendance(attendanceList2); + } else { + return {'totalLectures': 0, 'attendedLectures': 0}; + } +} + +Map calculateAttendance(List> attendanceList) { + int totalLectures = 0; + int attendedLectures = 0; + + for (var attendanceInfo in attendanceList) { + totalLectures += (attendanceInfo['total'] as num?)?.toInt() ?? 0; + attendedLectures += (attendanceInfo['present'] as num?)?.toInt() ?? 0; + } + + return { + 'totalLectures': totalLectures, + 'attendedLectures': attendedLectures, + }; +} + + +String getTextForCard(int at,int tt){ + double attended = at.toDouble(); + double total = tt.toDouble(); + int toAttend=0; + + + if (attended/total==0.75){ + return "You are Just on track, well done Champ"; + } else if(attended/total>0.75) { + while(1==1) { + double t=(attended)/(total+1); + if(t>=0.75){ + print("yes of 1"); + total++; + toAttend--; + } else { + break; + } + } + } else { + while(1==1) { + double t=(attended+1)/(total+1); + if(t<=0.75){ + print("yes of 2"); + total++; + attended++; + toAttend++; + } else { + break; + } + } + } + + + + return "By attending next ${toAttend} lectures, you will be above 75%"; +} From 6357f7a50848ecb477f38799a2b6b5c4d94bda91 Mon Sep 17 00:00:00 2001 From: Atharva Date: Sat, 20 Jul 2024 19:27:28 +0530 Subject: [PATCH 4/4] attendence done. but it keeps reloading. --- .../attendance_screen/attendance_screen.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index 0bf753c..d4acf05 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -231,6 +231,7 @@ class _AttendanceScreenState extends State { } Navigator.of(context).pop(); + _fetchAndSetAttendance(); }, child: Text('Update', style: TextStyle(color: Colors.blue)), ), @@ -248,12 +249,13 @@ class _AttendanceScreenState extends State { attendanceList.removeWhere((item) => item['subject_name'] == attendanceInfo['subject_name']); + await FirebaseFirestore.instance .collection("Attendance") .doc(FirebaseAuth.instance.currentUser!.uid) .update({'attendance': attendanceList}); } - + _fetchAndSetAttendance(); Navigator.of(context).pop(); }, child: Text('Delete', style: TextStyle(color: Colors.red)), @@ -344,11 +346,17 @@ class _AttendanceScreenState extends State { Center( child: Container( width: size.width * 0.88, - color: commonbgL4ightblack, - child: Text(getTextForCard(attendanceInfo['present'], attendanceInfo['total'])), + decoration: BoxDecoration( + border: Border.all(color: timePickerBorder, width: 1.0), + borderRadius: BorderRadius.circular(10.0), + color: timePickerBg, + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text(getTextForCard(attendanceInfo['present'], attendanceInfo['total']),style: TextStyle(color: Colors.grey),), + ), ), ), - const SizedBox(height: 10,), ], ), ),