Skip to content

Commit

Permalink
Merge pull request #221 from Shreya-Bhatia/main
Browse files Browse the repository at this point in the history
validation part in add subject
  • Loading branch information
Shreya-Bhatia authored Jul 23, 2024
2 parents c24b8ee + 549caf3 commit 0e44c90
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 70 deletions.
176 changes: 107 additions & 69 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
// ),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Text(getTextForCard(attendanceInfo['present'], attendanceInfo['total']),style: TextStyle(color: Colors.grey, fontSize: 10),),
child: Text(getTextForCard(attendanceInfo['present'], attendanceInfo['total']),style: TextStyle(color: Colors.grey, fontSize: 14),),
),
),
),
Expand Down Expand Up @@ -402,6 +402,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
TextEditingController totalLecturesController = TextEditingController();
TextEditingController attendedLecturesController = TextEditingController();

final _formKey = GlobalKey<FormState>();

return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15), // Increased corner radius
Expand All @@ -410,58 +412,90 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
'Add Subject',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
content: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
style: TextStyle(color: Colors.white), // Set text color to white
controller: subjectNameController,
decoration: InputDecoration(
focusColor: Colors.red,
labelText: 'Subject Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
content: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
validator: (val) {
if (val == null || val.isEmpty) {
return "Please enter some value";
}
},
style: TextStyle(color: Colors.white), // Set text color to white
controller: subjectNameController,
decoration: InputDecoration(
focusColor: Colors.red,
labelText: 'Subject Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
filled: true,
fillColor: Colors.transparent,
errorStyle: TextStyle(fontSize: 12),
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
),
filled: true,
fillColor: Colors.transparent,
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
),
),
SizedBox(height: 20),
TextField(
style: TextStyle(color: Colors.white), // Set text color to white
controller: attendedLecturesController,
decoration: InputDecoration(
labelText: 'Attended Lectures',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
SizedBox(height: 20),
TextFormField(
validator: (val) {
String totalLectures = totalLecturesController.text;

if (val == null || val.isEmpty) {
return "Please enter some value";
}
else if (totalLectures.isNotEmpty && int.parse(val) > int.parse(totalLectures)) {
return "Please enter correct value";
}

},
style: TextStyle(color: Colors.white), // Set text color to white
controller: attendedLecturesController,
decoration: InputDecoration(
labelText: 'Attended Lectures',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
filled: true,
fillColor: Colors.transparent,
errorStyle: TextStyle(fontSize: 12),
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
),
filled: true,
fillColor: Colors.transparent,
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
keyboardType: TextInputType.number,
),
keyboardType: TextInputType.number,
),
SizedBox(height: 20),
TextField(
style: TextStyle(color: Colors.white), // Set text color to white
controller: totalLecturesController,
decoration: InputDecoration(
labelText: 'Total Lectures Till Now',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
SizedBox(height: 20),
TextFormField(
validator: (val) {
String attendedLectures = attendedLecturesController.text;
if (val == null || val.isEmpty) {
return "Please enter some value";
}
else if ( attendedLectures.isNotEmpty && int.parse(val) < int.parse(attendedLectures)) {
return "Please enter correct value";
}

},
style: TextStyle(color: Colors.white), // Set text color to white
controller: totalLecturesController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Total Lectures Till Now',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
filled: true,
fillColor: Colors.transparent,
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
errorStyle: TextStyle(fontSize: 12),
),
filled: true,
fillColor: Colors.transparent,
contentPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
),
keyboardType: TextInputType.number,
),

],

],
),
),
),
),
Expand All @@ -474,28 +508,32 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
),
TextButton(
onPressed: () async{
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.addSubject(updatedSubject);
/*FirebaseFirestore.instance
.collection("Attendance")
.doc(FirebaseAuth.instance.currentUser!.uid)
.set({
'attendance': FieldValue.arrayUnion([{
'subject_name': subjectName,
'total': totalLectures,
'present': attendedLectures
}])
}, SetOptions(merge: true));
_fetchAndSetAttendance();*/
Navigator.of(context).pop();

if(_formKey.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.addSubject(updatedSubject);
/*FirebaseFirestore.instance
.collection("Attendance")
.doc(FirebaseAuth.instance.currentUser!.uid)
.set({
'attendance': FieldValue.arrayUnion([{
'subject_name': subjectName,
'total': totalLectures,
'present': attendedLectures
}])
}, SetOptions(merge: true));
_fetchAndSetAttendance();*/
Navigator.of(context).pop();
}

},
child: Text('Add', style: TextStyle(color: Colors.blue)),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/concession_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ConcessionProvider extends StateNotifier<String> {
await _concessionService.uploadPhoto(previousPassPhoto, "prevpass");
await _concessionService.applyConcession(concessionDetailsData,idCardURL2);


await getConcessionData();

state="Applied successfully";
await Future.delayed(const Duration(seconds: 2));
Expand Down

0 comments on commit 0e44c90

Please sign in to comment.