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

Added validation in update subject and fixed announcement overflow #248

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion lib/new_ui/screens/AnnouncementScreen/announcementscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,16 @@ class AnnouncementListItem extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(announcementModel.title.toString(),style: TextStyle(fontSize: 22,fontWeight: FontWeight.w500,color: Colors.white),),
Expanded(
child: Text(
announcementModel.title.toString(),
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w500,
color: Colors.white
),
)
),
if(announcementModel.docURL !=null || announcementModel.docURL !="")
InkWell(splashFactory: NoSplash.splashFactory,onTap: ()=>launchUrl(Uri.parse(announcementModel.docURL.toString(),),)
,child:Icon(Icons.link,color: Colors.blue,),
Expand Down
205 changes: 125 additions & 80 deletions lib/new_ui/screens/attendance_screen/attendance_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,101 +183,145 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
text: attendanceInfo["present"]
.toString());

final _updateformKey = GlobalKey<FormState>();

return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
title: Text('Update Subject'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: subjectNameController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'Subject Name',
labelStyle: TextStyle(
color: Colors.white70),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
content: Form(
key: _updateformKey,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
validator: (val) {
if (val == null || val.isEmpty) {
return "Please enter some value";
}
},
controller: subjectNameController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'Subject Name',
labelStyle: TextStyle(
color: Colors.white70),
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),
),
),
SizedBox(height: 20),
TextField(
controller:
attendedLecturesController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'Attended Lectures',
labelStyle: TextStyle(
color: Colors.white70),
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";
}
},
controller:
attendedLecturesController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: 'Attended Lectures',
labelStyle: TextStyle(
color: Colors.white70),
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(10),
),
filled: true,
errorStyle: TextStyle(fontSize: 12),
focusColor: Colors.red,
fillColor: Colors.transparent,
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(
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),
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";
}
},
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),
),
filled: true,
errorStyle: TextStyle(fontSize: 12),
focusColor: Colors.red,
fillColor: Colors.transparent,
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,
),
],
],
),
),
),
actions: <Widget>[
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.updateSubject(
attendanceList,
index,
updatedSubject);

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();
}


/*DocumentSnapshot doc = await FirebaseFirestore.instance
.collection("Attendance")
Expand Down Expand Up @@ -306,13 +350,14 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
}
}*/

Navigator.of(context).pop();

},
child: Text('Update',
style: TextStyle(color: Colors.blue)),
),
TextButton(
onPressed: () async {

await AttendanceService.deleteSubject(
attendanceList, index);

Expand Down
Loading