From 51657fc691b25bcd8d52703983e12d0881fca6a6 Mon Sep 17 00:00:00 2001 From: SayedZeeshanHyder Date: Sat, 20 Jul 2024 14:13:21 +0530 Subject: [PATCH] Changes Made in Notes Screen and Added Stream Builder in Attendance Screen --- .../attendance_screen/attendance_screen.dart | 156 ++++++++++++++++-- .../widgets/attendance_subject_widget.dart | 105 ------------ .../widgets/attendanceservice.dart | 21 +++ .../screens/main_screen/main_screen.dart | 6 +- .../widgets/main_bottom_nav_bar.dart | 2 +- .../screens/notes_screen/notes_screen.dart | 2 +- .../railway_screen/railway_screen.dart | 5 +- 7 files changed, 172 insertions(+), 125 deletions(-) create mode 100644 lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index df0197c6..4a01d70b 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -1,17 +1,22 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:tsec_app/new_ui/colors.dart'; import 'package:tsec_app/new_ui/screens/attendance_screen/widgets/attendance_subject_widget.dart'; +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 { - const AttendanceScreen({super.key}); + final FirebaseAuth auth = FirebaseAuth.instance; + AttendanceService attendanceService = AttendanceService(); @override Widget build(BuildContext context) { - var present =8; - var totalLec=10; + var present = 8; + var totalLec = 10; //put the attendance from a provider here - double attendance = present/totalLec; + double attendance = present / totalLec; var size = MediaQuery.of(context).size; return SingleChildScrollView( child: Padding( @@ -23,7 +28,9 @@ class AttendanceScreen extends StatelessWidget { // attendance < 0.75 ? 'Your attendance is low' : 'Your attendance is good', // style: TextStyle(color: Colors.white, fontSize: 20), // ), - const SizedBox(height: 30,), + const SizedBox( + height: 30, + ), Stack( children: [ Positioned.fill( @@ -33,15 +40,15 @@ class AttendanceScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - '' , + '', style: TextStyle(color: Colors.white, fontSize: 4), - ), + ), Text( - '${attendance * 100}%' , + '${attendance * 100}%', style: TextStyle(color: Colors.white, fontSize: 17), - ), + ), Text( - '${present}/${totalLec}' , + '${present}/${totalLec}', style: TextStyle(color: Colors.white, fontSize: 14), ), ], @@ -54,7 +61,8 @@ class AttendanceScreen extends StatelessWidget { child: CircularProgressIndicator( value: attendance, backgroundColor: Colors.white, - valueColor: AlwaysStoppedAnimation(oldDateSelectBlue), + valueColor: + AlwaysStoppedAnimation(oldDateSelectBlue), strokeWidth: 3, strokeAlign: BorderSide.strokeAlignInside, strokeCap: StrokeCap.butt, @@ -62,10 +70,130 @@ class AttendanceScreen extends StatelessWidget { ), ], ), - const SizedBox(height: 20,), + const SizedBox( + height: 20, + ), //put the subject attendance cards from here - const SizedBox(height: 10,), - AttendanceSubjectWidget(attendance: 0.75), + 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)), + ), + ), + 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,), + ], + ), + ), + ) + ); + }, + ); + }), ], ), ), diff --git a/lib/new_ui/screens/attendance_screen/widgets/attendance_subject_widget.dart b/lib/new_ui/screens/attendance_screen/widgets/attendance_subject_widget.dart index a9b2fd6a..e69de29b 100644 --- a/lib/new_ui/screens/attendance_screen/widgets/attendance_subject_widget.dart +++ b/lib/new_ui/screens/attendance_screen/widgets/attendance_subject_widget.dart @@ -1,105 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:tsec_app/new_ui/colors.dart'; - -class AttendanceSubjectWidget extends StatelessWidget { - final double attendance; - const AttendanceSubjectWidget({super.key, required this.attendance}); - - @override - Widget build(BuildContext context) { - var size = MediaQuery.of(context).size; - - 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: [ - const Row( - //crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text( - '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( - '5/10', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - Text( - '50%', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - ], - ), - const SizedBox(height: 10,), - LinearProgressIndicator( - value: attendance, - backgroundColor: Colors.white, - valueColor: const AlwaysStoppedAnimation(Colors.blue), - ), - const SizedBox(height: 15,), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - onPressed: (){}, - 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: (){}, - 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,), - ], - ), - ), - ) - ); - } -} diff --git a/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart b/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart new file mode 100644 index 00000000..876c05d4 --- /dev/null +++ b/lib/new_ui/screens/attendance_screen/widgets/attendanceservice.dart @@ -0,0 +1,21 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; + +class AttendanceService{ + + static FirebaseAuth auth = FirebaseAuth.instance; + static CollectionReference firestore = FirebaseFirestore.instance.collection("Attendance"); + + static markPresent(List attendanceList,int index){ + attendanceList[index]['present']++; + print(attendanceList[index]['present']); + firestore.doc(auth.currentUser!.uid).set({"attendance":attendanceList}); + } + + static markAbsent(List attendanceList,int index){ + attendanceList[index]['total']++; + print(attendanceList[index]['total']); + firestore.doc(auth.currentUser!.uid).set({"attendance":attendanceList}); + } + +} \ No newline at end of file diff --git a/lib/new_ui/screens/main_screen/main_screen.dart b/lib/new_ui/screens/main_screen/main_screen.dart index a6112aba..2b764112 100644 --- a/lib/new_ui/screens/main_screen/main_screen.dart +++ b/lib/new_ui/screens/main_screen/main_screen.dart @@ -83,7 +83,7 @@ class _MainScreenState extends ConsumerState { ), "notes": const NotesScreen(), "timetable": const TimeTable(), - "attendance": const AttendanceScreen(), + "attendance": AttendanceScreen(), "concession": const RailwayConcessionScreen(), "profile": ProfilePage( justLoggedIn: false, @@ -163,7 +163,7 @@ class _MainScreenState extends ConsumerState { ), const NotesScreen(), ProfilePage(justLoggedIn: false), - const AttendanceScreen(), + AttendanceScreen(), const RailwayConcessionScreen(), const TPCScreen(), const CommitteesScreen(), @@ -185,7 +185,7 @@ class _MainScreenState extends ConsumerState { }, ), const NotesScreen(), - const AttendanceScreen(), + AttendanceScreen(), const RailwayConcessionScreen(), ProfilePage(justLoggedIn: false), const TPCScreen(), diff --git a/lib/new_ui/screens/main_screen/widgets/main_bottom_nav_bar.dart b/lib/new_ui/screens/main_screen/widgets/main_bottom_nav_bar.dart index 0c8126ff..cd1a9be5 100644 --- a/lib/new_ui/screens/main_screen/widgets/main_bottom_nav_bar.dart +++ b/lib/new_ui/screens/main_screen/widgets/main_bottom_nav_bar.dart @@ -56,7 +56,7 @@ class _HomeScreenState extends ConsumerState { ), "notes": NotesScreen(), "timetable": const TimeTable(), - "attendance": const AttendanceScreen(), + "attendance": AttendanceScreen(), "concession": const RailwayConcessionScreen(), "profile": ProfilePage( justLoggedIn: false, diff --git a/lib/new_ui/screens/notes_screen/notes_screen.dart b/lib/new_ui/screens/notes_screen/notes_screen.dart index 496540b7..b019e000 100644 --- a/lib/new_ui/screens/notes_screen/notes_screen.dart +++ b/lib/new_ui/screens/notes_screen/notes_screen.dart @@ -52,7 +52,7 @@ class _NotesScreenState extends ConsumerState { title: title!, // description: descriptionController.text, description: description!, - time: dmyDate(DateTime.now()), + time: DateTime.now(), subject: subject!, professorName: user.facultyModel!.name, targetClasses: [ diff --git a/lib/new_ui/screens/railway_screen/railway_screen.dart b/lib/new_ui/screens/railway_screen/railway_screen.dart index 26fb8240..fc32a59b 100644 --- a/lib/new_ui/screens/railway_screen/railway_screen.dart +++ b/lib/new_ui/screens/railway_screen/railway_screen.dart @@ -554,6 +554,10 @@ class _RailwayConcessionScreenState ), ), + SizedBox( + height: size.height*0.04, + ), + Container( width: size.width * 0.7, child: InkWell( @@ -739,7 +743,6 @@ class _RailwayConcessionScreenState ), Container( width: size.width, - //height: size.height*0.4, decoration: const BoxDecoration( color: oldDateSelectBlue, border: Border.symmetric(vertical: BorderSide(color: Colors.white),),