Skip to content

Commit

Permalink
Changes Made in Notes Screen and Added Stream Builder in Attendance S…
Browse files Browse the repository at this point in the history
…creen
  • Loading branch information
SayedZeeshanHyder committed Jul 20, 2024
1 parent 7d8127a commit 51657fc
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 125 deletions.
156 changes: 142 additions & 14 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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(
Expand All @@ -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),
),
],
Expand All @@ -54,18 +61,139 @@ class AttendanceScreen extends StatelessWidget {
child: CircularProgressIndicator(
value: attendance,
backgroundColor: Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(oldDateSelectBlue),
valueColor:
AlwaysStoppedAnimation<Color>(oldDateSelectBlue),
strokeWidth: 3,
strokeAlign: BorderSide.strokeAlignInside,
strokeCap: StrokeCap.butt,
),
),
],
),
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<String, dynamic>;
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<Color>(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,),
],
),
),
)
);
},
);
}),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Color>(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,),
],
),
),
)
);
}
}
Original file line number Diff line number Diff line change
@@ -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});
}

}
6 changes: 3 additions & 3 deletions lib/new_ui/screens/main_screen/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _MainScreenState extends ConsumerState<MainScreen> {
),
"notes": const NotesScreen(),
"timetable": const TimeTable(),
"attendance": const AttendanceScreen(),
"attendance": AttendanceScreen(),
"concession": const RailwayConcessionScreen(),
"profile": ProfilePage(
justLoggedIn: false,
Expand Down Expand Up @@ -163,7 +163,7 @@ class _MainScreenState extends ConsumerState<MainScreen> {
),
const NotesScreen(),
ProfilePage(justLoggedIn: false),
const AttendanceScreen(),
AttendanceScreen(),
const RailwayConcessionScreen(),
const TPCScreen(),
const CommitteesScreen(),
Expand All @@ -185,7 +185,7 @@ class _MainScreenState extends ConsumerState<MainScreen> {
},
),
const NotesScreen(),
const AttendanceScreen(),
AttendanceScreen(),
const RailwayConcessionScreen(),
ProfilePage(justLoggedIn: false),
const TPCScreen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _HomeScreenState extends ConsumerState<MainBottomNavBar> {
),
"notes": NotesScreen(),
"timetable": const TimeTable(),
"attendance": const AttendanceScreen(),
"attendance": AttendanceScreen(),
"concession": const RailwayConcessionScreen(),
"profile": ProfilePage(
justLoggedIn: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/new_ui/screens/notes_screen/notes_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _NotesScreenState extends ConsumerState<NotesScreen> {
title: title!,
// description: descriptionController.text,
description: description!,
time: dmyDate(DateTime.now()),
time: DateTime.now(),
subject: subject!,
professorName: user.facultyModel!.name,
targetClasses: [
Expand Down
5 changes: 4 additions & 1 deletion lib/new_ui/screens/railway_screen/railway_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ class _RailwayConcessionScreenState
),
),

SizedBox(
height: size.height*0.04,
),

Container(
width: size.width * 0.7,
child: InkWell(
Expand Down Expand Up @@ -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),),
Expand Down

0 comments on commit 51657fc

Please sign in to comment.