Skip to content

Commit

Permalink
fixed being able to add 2 entries to the attendance by pressing add t…
Browse files Browse the repository at this point in the history
…wice
  • Loading branch information
CosmicRaptor committed Aug 1, 2024
1 parent 7f19c09 commit b894d6a
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
bool isEnabled = true;
return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore.instance
Expand Down Expand Up @@ -185,7 +184,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
.toString());

final _updateformKey = GlobalKey<FormState>();

bool isEnabled = true;
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
Expand All @@ -203,6 +202,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
return "Please enter some value";
}
},
enabled: isEnabled,
controller: subjectNameController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
Expand Down Expand Up @@ -238,6 +238,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
controller:
attendedLecturesController,
style: TextStyle(color: Colors.white),
enabled: isEnabled,
decoration: InputDecoration(
labelText: 'Attended Lectures',
border: OutlineInputBorder(
Expand All @@ -256,6 +257,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
),
SizedBox(height: 20),
TextFormField(
enabled: isEnabled,
validator: (val) {
String attendedLectures =
attendedLecturesController.text;
Expand Down Expand Up @@ -294,31 +296,34 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
),
actions: <Widget>[
TextButton(
onPressed: () async {

if (_updateformKey.currentState!.validate())
{
String subjectName =
subjectNameController.text;
int totalLectures = int.parse(
totalLecturesController.text);
int attendedLectures = int.parse(
attendedLecturesController.text);

Map<String, dynamic> updatedSubject = {
"subject_name": subjectName,
"total": totalLectures,
"present": attendedLectures
};

await AttendanceService.updateSubject(
attendanceList,
index,
updatedSubject);

Navigator.of(context).pop();
onPressed: () {
if(isEnabled) {
isEnabled = false;
if (_updateformKey.currentState!
.validate()) {
String subjectName =
subjectNameController.text;
int totalLectures = int.parse(
totalLecturesController.text);
int attendedLectures = int.parse(
attendedLecturesController
.text);

Map<String, dynamic>
updatedSubject = {
"subject_name": subjectName,
"total": totalLectures,
"present": attendedLectures
};

AttendanceService
.updateSubject(attendanceList,
index, updatedSubject);

Navigator.of(context).pop();
}
}

isEnabled = false;

/*DocumentSnapshot doc = await FirebaseFirestore.instance
.collection("Attendance")
Expand Down Expand Up @@ -353,9 +358,9 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
style: TextStyle(color: Colors.blue)),
),
TextButton(
onPressed: () async {
onPressed: () {

await AttendanceService.deleteSubject(
AttendanceService.deleteSubject(
attendanceList, index);

/*DocumentSnapshot doc = await FirebaseFirestore.instance
Expand Down Expand Up @@ -669,7 +674,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
child: Text('Cancel', style: TextStyle(color: Colors.red)),
),
TextButton(
onPressed: () async {
onPressed: () {
if (_formKey.currentState!.validate()) {
String subjectName = subjectNameController.text;
int totalLectures =
Expand All @@ -682,7 +687,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
"total": totalLectures,
"present": attendedLectures
};
await AttendanceService.addSubject(updatedSubject);
AttendanceService.addSubject(updatedSubject);
/*FirebaseFirestore.instance
.collection("Attendance")
.doc(FirebaseAuth.instance.currentUser!.uid)
Expand Down

0 comments on commit b894d6a

Please sign in to comment.