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 most of the issues with attendance screen #249

Merged
merged 3 commits into from
Aug 1, 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
90 changes: 47 additions & 43 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:ffi';

import 'package:flutter/services.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -184,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 @@ -202,12 +202,11 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
return "Please enter some value";
}
},
enabled: isEnabled,
controller: subjectNameController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'Subject Name',
labelStyle: TextStyle(
color: Colors.white70),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
Expand All @@ -234,13 +233,14 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
return "Please enter correct value";
}
},
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
controller:
attendedLecturesController,
style: TextStyle(color: Colors.white),
enabled: isEnabled,
decoration: InputDecoration(
labelText: 'Attended Lectures',
labelStyle: TextStyle(
color: Colors.white70),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
Expand All @@ -254,10 +254,10 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
horizontal: 15,
vertical: 10),
),
keyboardType: TextInputType.number,
),
SizedBox(height: 20),
TextFormField(
enabled: isEnabled,
validator: (val) {
String attendedLectures =
attendedLecturesController.text;
Expand All @@ -269,13 +269,13 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
return "Please enter correct value";
}
},
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
controller: totalLecturesController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText:
'Total Lectures Till Now',
labelStyle: TextStyle(
color: Colors.white70),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
Expand All @@ -289,39 +289,41 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
horizontal: 15,
vertical: 10),
),
keyboardType: TextInputType.number,
),
],
),
),
),
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 @@ -356,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 @@ -615,6 +617,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
style: TextStyle(color: Colors.white),
// Set text color to white
controller: attendedLecturesController,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: InputDecoration(
labelText: 'Attended Lectures',
border: OutlineInputBorder(
Expand All @@ -626,25 +630,25 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
contentPadding: EdgeInsets.symmetric(
horizontal: 15, vertical: 10),
),
keyboardType: TextInputType.number,
),
SizedBox(height: 20),
TextFormField(
validator: (val) {
String attendedLectures =
attendedLecturesController.text;
int attendedLectures =
int.parse(attendedLecturesController.text) ?? 0;
if (val == null || val.isEmpty) {
return "Please enter some value";
} else if (attendedLectures.isNotEmpty &&
} else if (attendedLectures !=0 &&
int.parse(val) <
int.parse(attendedLectures)) {
attendedLectures) {
return "Please enter correct value";
}
},
style: TextStyle(color: Colors.white),
// Set text color to white
controller: totalLecturesController,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: InputDecoration(
labelText: 'Total Lectures Till Now',
border: OutlineInputBorder(
Expand All @@ -670,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 @@ -683,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
Loading