From a88e771144b309a4f9d74e555e7bd2e0905f7f06 Mon Sep 17 00:00:00 2001 From: SayedZeeshanHyder Date: Tue, 23 Jul 2024 21:42:14 +0530 Subject: [PATCH] Fixed the Circular Stack Above --- .../attendance_screen/attendance_screen.dart | 177 +++++++++--------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index 4570dd9..94aa855 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -46,90 +46,91 @@ class _AttendanceScreenState extends State { body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - 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( - '${((attendedLectures/totalLectures) * 100).toStringAsFixed(2)}%', - style: TextStyle(color: Colors.white, fontSize: 25), - ), - Text( - '${attendedLectures}/${totalLectures}', - style: TextStyle(color: Colors.white, fontSize: 15), - ), - ], - ), + child: 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; + if (documentSnapshot.data() == null) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset('assets/images/attendance.png', + width: 250, + ), + SizedBox(height: 20), + Text( + "Please add Subject", + style: TextStyle(color: Colors.white, fontSize: 18), + ), + ], ), - ), - SizedBox( - width: 150, - height: 150, - child: CircularProgressIndicator( - value: totalLectures==0?0:(attendedLectures/totalLectures), - backgroundColor: Colors.white, - valueColor: - AlwaysStoppedAnimation(oldDateSelectBlue), - strokeWidth: 5, - strokeAlign: BorderSide.strokeAlignInside, - strokeCap: StrokeCap.round, + ); + } + + var data = documentSnapshot.data() as Map; + List attendanceList = data['attendance']; + //List> attendanceList2 = attendanceList.cast>(); + Map circularMap = calculateAttendance(attendanceList); + + return Column( + children: [ + const SizedBox( + height: 30, ), - ), - ], - ), - 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; - if (documentSnapshot.data() == null) { - return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset('assets/images/attendance.png', - width: 250, - ), - SizedBox(height: 20), - Text( - "Please add Subject", - style: TextStyle(color: Colors.white, fontSize: 18), + Stack( + children: [ + Positioned.fill( + child: Align( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + '', + style: TextStyle(color: Colors.white, fontSize: 4), + ), + Text( + '${((circularMap["attendedLectures"]/circularMap["totalLectures"]) * 100).toStringAsFixed(2)}%', + style: TextStyle(color: Colors.white, fontSize: 25), + ), + Text( + '${(circularMap["attendedLectures"]/circularMap["totalLectures"]).toStringAsFixed(2)}', + style: TextStyle(color: Colors.white, fontSize: 15), + ), + ], ), - ], + ), ), - ); - } - - var data = documentSnapshot.data() as Map; - List attendanceList = data['attendance']; - //List> attendanceList2 = attendanceList.cast>(); - - return ListView.builder( + SizedBox( + width: 150, + height: 150, + child: CircularProgressIndicator( + value: circularMap["totalLectures"]==0 ?0:(circularMap["attendedLectures"]/circularMap["totalLectures"]), + backgroundColor: Colors.white, + valueColor: + AlwaysStoppedAnimation(oldDateSelectBlue), + strokeWidth: 5, + strokeAlign: BorderSide.strokeAlignInside, + strokeCap: StrokeCap.round, + ), + ), + ], + ), + const SizedBox( + height: 20, + ), + //put the subject attendance cards from here + const SizedBox( + height: 10, + ), + ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: attendanceList.length, @@ -383,13 +384,13 @@ class _AttendanceScreenState extends State { ), ); }, - ); - }), - SizedBox( - height: 20, - ), - ], - ), + ), + SizedBox( + height: 20, + ), + ], + ); + }), ), ), floatingActionButton: FloatingActionButton( @@ -532,7 +533,7 @@ Future> fetchAttendanceData() async { } } -Map calculateAttendance(List> attendanceList) { +Map calculateAttendance(List attendanceList) { int totalLectures = 0; int attendedLectures = 0;