Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Circular Stack Above #220

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 89 additions & 88 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,90 +46,91 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
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: <Widget>[
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<Color>(oldDateSelectBlue),
strokeWidth: 5,
strokeAlign: BorderSide.strokeAlignInside,
strokeCap: StrokeCap.round,
);
}

var data = documentSnapshot.data() as Map<String, dynamic>;
List attendanceList = data['attendance'];
//List<Map<String, dynamic>> attendanceList2 = attendanceList.cast<Map<String, dynamic>>();
Map<String,dynamic> 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: <Widget>[
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<String, dynamic>;
List attendanceList = data['attendance'];
//List<Map<String, dynamic>> attendanceList2 = attendanceList.cast<Map<String, dynamic>>();

return ListView.builder(
SizedBox(
width: 150,
height: 150,
child: CircularProgressIndicator(
value: circularMap["totalLectures"]==0 ?0:(circularMap["attendedLectures"]/circularMap["totalLectures"]),
backgroundColor: Colors.white,
valueColor:
AlwaysStoppedAnimation<Color>(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,
Expand Down Expand Up @@ -383,13 +384,13 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
),
);
},
);
}),
SizedBox(
height: 20,
),
],
),
),
SizedBox(
height: 20,
),
],
);
}),
),
),
floatingActionButton: FloatingActionButton(
Expand Down Expand Up @@ -532,7 +533,7 @@ Future<Map<String, int>> fetchAttendanceData() async {
}
}

Map<String, int> calculateAttendance(List<Map<String, dynamic>> attendanceList) {
Map<String, int> calculateAttendance(List attendanceList) {
int totalLectures = 0;
int attendedLectures = 0;

Expand Down
Loading