}" is correctly retrieved "I/flutter ( 4399): seanceId value: 31" I want it retrieved in the presence object sent in the list bt this "Future createPresenceList(List presenceList) async {
try {
final payload = presenceList
.map((presence) => presence.toJson())
.toList();
print('Request Payload: $payload');
final response = await http.post(
Uri.parse('$endpointUrl/creerfichepresence'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${await Login.LoginLogic.getToken()}',
},
body: jsonEncode(payload),
);
print('Response Status Code: ${response.statusCode}');
if (response.statusCode == 200) {
// Presence list created successfully
// Handle the response if needed
} else {
throw Exception('Failed to create presence list');
}
} catch (e) {
throw Exception('Error creating presence list: $e');
}
}" please update this "class Seance {
final int? seanceId;
final String dateSeance;
final String tempsDebut;
final String tempsFin;
final int classeId;
final int enseignantId;
final int matiereAttribueeId;
" in order to use the key "id" and handling it by the seance and presence objects instead of seanceId
Please update the Presence and Seance classes to use the id key instead of seanceId, and update the relevant code to reflect this change.
Updated Seance class:
class Seance {
final int? id; // Use "id" key instead of "seanceId"
final String dateSeance;
final String tempsDebut;
final String tempsFin;
final int classeId;
final int enseignantId;
final int matiereAttribueeId;
Seance({
this.id, // Use "id" key instead of "seanceId"
required this.dateSeance,
required this.tempsDebut,
required this.tempsFin,
required this.classeId,
required this.enseignantId,
required this.matiereAttribueeId,
});
factory Seance.fromJson(Map<String, dynamic> json) {
return Seance(
id: json['id'], // Use "id" key instead of "seanceId"
dateSeance: json['dateSeance'],
tempsDebut: json['tempsDebut'],
tempsFin: json['tempsFin'],
classeId: json['classeId'],
enseignantId: json['enseignantId'],
matiereAttribueeId: json['matiereAttribueeId'],
);
}
@override
String toString() {
return 'Seance(id: $id, dateSeance: $dateSeance, tempsDebut: $tempsDebut, tempsFin: $tempsFin, classeId: $classeId,'
' enseignantId: $enseignantId, matiereAttribueeId: $matiereAttribueeId)';
}
}
Updated Presence class:
class Presence {
final bool present;
final int etudiantId;
final int seanceId;
Presence({
required this.present,
required this.etudiantId,
required this.seanceId,
});
Map<String, dynamic> toJson() {
return {
'present': present,
'etudiantId': etudiantId.toString(),
'seanceId': seanceId.toString(),
};
}
factory Presence.fromJson(Map<String, dynamic> json) {
return Presence(
present: json['present'],
etudiantId: json['etudiantId'],
seanceId: json['id'], // Use "id" key instead of "seanceId"
);
}
}
Now, when you create a new instance of Presence and set the seanceId property, use selectedSeance?.id instead of selectedSeance?.seanceId. Similarly, when you create Presence objects from JSON data, use json['id'] instead of json['seanceId']. And when you print the selected Seance object, use .id instead of .seanceId.
For example:
presenceList.add(Presence(
etudiantId: etudiant.etudiantId,
seanceId: selectedSeance?.id, // Use "id" key instead of "seanceId"
present: etudiant.isPresent,
));
...
factory Presence.fromJson(Map<String, dynamic> json) {
return Presence(
present: json['present'],
etudiantId: json['etudiantId'],
seanceId: json['id'], // Use "id" key instead of "seanceId"
);
}
...
print('Selected Seance: ${selectedSeance?.toString()}'); // Use ".id" instead of ".seanceId"