Skip to content

Commit

Permalink
feat: Delete student.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ghtbyte committed Oct 3, 2023
1 parent 4d5ed9f commit dcfec82
Showing 1 changed file with 96 additions and 1 deletion.
97 changes: 96 additions & 1 deletion lib/pages/Teacher/Classes/TurmaExemplo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:js_interop';
import 'package:assessments_app/InovWidgets/ChartData.dart';
import 'package:assessments_app/InovWidgets/LegendWidget.dart';
import 'package:assessments_app/pages/Teacher/Assessments/GenMultipleSelfAssessments.dart';
Expand Down Expand Up @@ -750,6 +749,102 @@ class _TurmaExemploState extends State<TurmaExemplo>
),
);
},
onLongPress: () {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text(
"Delete this student"),
content: Text(
"Are you sure you want to remove this?"),
actions: [
TextButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty
.all<Color>(
Colors
.blue),
),
onPressed: () {
Navigator.of(context,
rootNavigator:
true)
.pop();
},
child: Text(
AppLocalizations.of(
context)!
.cancel),
),
TextButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty
.all<Color>(
Colors
.blue),
),
onPressed: () async {
Navigator.of(context,
rootNavigator:
true)
.pop();
var x;
if (studs[index] !=
namedStuds[studs[
index]
.toString()]) {
x = studs[index]
.toString();
} else {
x = namedStuds[studs[
index]
.toString()]
.toString();
}
print(x);

// Delete the class from /classes
// This does not removed subcollections

// Delete assessments in /assessments

await FirebaseFirestore
.instance
.collection(
'classes')
.doc(widget
.passedClassName)
.update({
'StudentList':
FieldValue
.arrayRemove(
[x]),
});
await FirebaseFirestore
.instance
.collection(
'classes')
.doc(widget
.passedClassName)
.update({
'NumStudents':
FieldValue
.increment(
-1),
});
setState(() {});
},
child: Text(
AppLocalizations.of(
context)!
.delete,
),
),
],
));
},
);
},
),
Expand Down

0 comments on commit dcfec82

Please sign in to comment.