diff --git a/lib/new_ui/screens/attendance_screen/attendance_screen.dart b/lib/new_ui/screens/attendance_screen/attendance_screen.dart index 94aa855..2110c15 100644 --- a/lib/new_ui/screens/attendance_screen/attendance_screen.dart +++ b/lib/new_ui/screens/attendance_screen/attendance_screen.dart @@ -373,7 +373,7 @@ class _AttendanceScreenState extends State { // ), 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),), ), ), ), @@ -402,6 +402,8 @@ class _AttendanceScreenState extends State { TextEditingController totalLecturesController = TextEditingController(); TextEditingController attendedLecturesController = TextEditingController(); + final _formKey = GlobalKey(); + return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), // Increased corner radius @@ -410,58 +412,90 @@ class _AttendanceScreenState extends State { '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, - ), - - ], + + ], + ), ), ), ), @@ -474,28 +508,32 @@ class _AttendanceScreenState extends State { ), TextButton( onPressed: () async{ - String subjectName = subjectNameController.text; - int totalLectures = int.parse(totalLecturesController.text); - int attendedLectures = int.parse(attendedLecturesController.text); - - Map 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 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)), ), diff --git a/lib/provider/concession_provider.dart b/lib/provider/concession_provider.dart index 97b1878..c72823e 100644 --- a/lib/provider/concession_provider.dart +++ b/lib/provider/concession_provider.dart @@ -60,7 +60,7 @@ class ConcessionProvider extends StateNotifier { await _concessionService.uploadPhoto(previousPassPhoto, "prevpass"); await _concessionService.applyConcession(concessionDetailsData,idCardURL2); - + await getConcessionData(); state="Applied successfully"; await Future.delayed(const Duration(seconds: 2));