now that this "Future<void> fetchSeances() async {
    try {
      final response = await http.get(
        Uri.parse('$endpointUrl/listermesseancescejour'),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ${await Login.LoginLogic.getToken()}',
        },
      );

      if (response.statusCode == 200) {
        final List<dynamic> seancesJson = jsonDecode(response.body);
        setState(() {
          seances = seancesJson.map((json) {
            print('seanceId value: ${json['id']}'); // Print seanceId value
            return Seance.fromJson(json);
          }).toList();

          if (seances.isNotEmpty) {
            selectedSeance = seances[0];
            fetchEtudiantUsernamesByClasseId(selectedSeance!.classeId);
          }
        });
      } else {
        throw Exception('Failed to fetch seances');
      }
    } catch (e) {
      throw Exception('Error fetching seances: $e');
    }
  }" is correctly retrieved "I/flutter ( 4399): seanceId value: 31" I want it retrieved in the presence object sent in the list bt this "Future<void> createPresenceList(List<Presence> 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;

  Seance({
    this.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(
      seanceId: json['seanceId'], // Remove null coalescing operator
      dateSeance: json['dateSeance'],
      tempsDebut: json['tempsDebut'],
      tempsFin: json['tempsFin'],
      classeId: json['classeId'],
      enseignantId: json['enseignantId'],
      matiereAttribueeId: json['matiereAttribueeId'],
    );
  }

  @override
  String toString() {
    return 'Seance(seanceId: $seanceId, dateSeance: $dateSeance, tempsDebut: $tempsDebut, tempsFin: $tempsFin, classeId: $classeId,'
        ' enseignantId: $enseignantId, matiereAttribueeId: $matiereAttribueeId)';
  }
}

class Etudiant {
  final int etudiantId;
  final String username;
  bool isPresent;
  bool isAbsent;

  Etudiant({
    required this.etudiantId,
    required this.username,
    this.isPresent = false,
    this.isAbsent = false,
  });
}

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(), // Convert to String
      'seanceId': seanceId.toString(), // Convert to String
    };
  }

}

class MarquerManuellementPresence extends StatefulWidget {
  @override
  _MarquerManuellementPresenceState createState() =>
      _MarquerManuellementPresenceState();
}

class _MarquerManuellementPresenceState
    extends State<MarquerManuellementPresence> {
  List<Seance> seances = [];
  List<Etudiant> etudiants = [];
  Seance? selectedSeance;
  bool isButtonEnabled = false;

  @override
  void initState() {
    super.initState();
    fetchSeances();
  }

  Future<void> fetchSeances() async {
    try {
      final response = await http.get(
        Uri.parse('$endpointUrl/listermesseancescejour'),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ${await Login.LoginLogic.getToken()}',
        },
      );

      if (response.statusCode == 200) {
        final List<dynamic> seancesJson = jsonDecode(response.body);
        setState(() {
          seances = seancesJson.map((json) {
            print('seanceId value: ${json['id']}'); // Print seanceId value
            return Seance.fromJson(json);
          }).toList();

          if (seances.isNotEmpty) {
            selectedSeance = seances[0];
            fetchEtudiantUsernamesByClasseId(selectedSeance!.classeId);
          }
        });
      } else {
        throw Exception('Failed to fetch seances');
      }
    } catch (e) {
      throw Exception('Error fetching seances: $e');
    }
  }


  Future<void> fetchEtudiantUsernamesByClasseId(int classeId) async {
    try {
      final response = await http.get(
        Uri.parse('$endpointUrl/etudiants/$classeId/usernames'),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ${await Login.LoginLogic.getToken()}',
        },
      );

      if (response.statusCode == 200) {
        final List<dynamic> responseBody = jsonDecode(response.body);
        setState(() {
          etudiants = responseBody
              .map((etudiantMap) => Etudiant(
            etudiantId: etudiantMap['etudiantId'],
            username: etudiantMap['username'],
          ))
              .toList();
          isButtonEnabled = checkIfAtLeastOneChecked(etudiants);
        });
      } else {
        throw Exception('Failed to fetch etudiant usernames');
      }
    } catch (e) {
      throw Exception('Error fetching etudiant usernames: $e');
    }
  }

  bool checkIfAtLeastOneChecked(List<Etudiant> etudiants) {
    for (var etudiant in etudiants) {
      if (etudiant.isPresent || etudiant.isAbsent) {
        return true;
      }
    }
    return false;
  }

  Future<void> createPresenceList(List<Presence> 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');
    }
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Fiche de présence"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            SizedBox(height: 20),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              child: Center(
                child: Text(
                  "Veuillez choisir une des séances d'aujourd'hui pour laquelle vous voulez marquer la présence",
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
            SizedBox(height: 20),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16.0),
              child: DropdownButton<Seance>(
                value: selectedSeance,
                items: seances.map((seance) {
                  final dropdownText = '${seance.tempsDebut} - ${seance.tempsFin}';
                  return DropdownMenuItem<Seance>(
                    value: seance,
                    child: Text(dropdownText),
                  );
                }).toList(),
                onChanged: (value) async {
                  setState(() {
                    selectedSeance = value;
                    fetchEtudiantUsernamesByClasseId(selectedSeance!.classeId);
                    isButtonEnabled = checkIfAtLeastOneChecked(etudiants);
                  });
                },
              ),
            ),
            SizedBox(height: 20),
            Expanded(
              child: SingleChildScrollView(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Table(
                    border: TableBorder.all(color: Colors.black, width: 1.0),
                    children: [
                      TableRow(
                        children: [
                          TableCell(
                            child: Center(child: Text("Nom d'étudiant")),
                          ),
                          TableCell(
                            child: Center(child: Text('Présent')),
                          ),
                          TableCell(
                            child: Center(child: Text('Absent')),
                          ),
                        ],
                      ),
                      ...etudiants.map((etudiant) {
                        return TableRow(
                          children: [
                            TableCell(
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Center(child: Text(etudiant.username)),
                              ),
                            ),
                            TableCell(
                              child: Checkbox(
                                value: etudiant.isPresent,
                                onChanged: (value) {
                                  setState(() {
                                    etudiant.isPresent = value!;
                                    isButtonEnabled =
                                        checkIfAtLeastOneChecked(etudiants);
                                  });
                                },
                              ),
                            ),
                            TableCell(
                              child: Checkbox(
                                value: etudiant.isAbsent,
                                onChanged: (value) {
                                  setState(() {
                                    etudiant.isAbsent = value!;
                                    isButtonEnabled =
                                        checkIfAtLeastOneChecked(etudiants);
                                  });
                                },
                              ),
                            ),
                          ],
                        );
                      }).toList(),
                    ],
                  ),
                ),
              ),
            ),
            SizedBox(height: 20),
            ElevatedButton(
              onPressed: isButtonEnabled
                  ? () async {
                List<Presence> presenceList = [];
                for (var etudiant in etudiants) {
                  if (selectedSeance != null) {
                    presenceList.add(Presence(
                      etudiantId: etudiant.etudiantId,
                      seanceId: selectedSeance!.seanceId!, // Use the selected seanceId
                      present: etudiant.isPresent,
                    ));
                  }
                }

                // Print selectedSeance object
                print('Selected Seance: ${selectedSeance.toString()}');

                try {
                  await createPresenceList(presenceList);
                  // Handle successful presence list creation
                } catch (e) {
                  // Handle error
                }
              }
                  : null,
              child: Text("Marquer la présence"),
            ),
            SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                // Handle "Enregistrer comme pdf" button press
              },
              child: Text("Enregistrer comme PDF"),
            ),
          ],
        ),
      ),
    );
  }
}

" in order to use the key "id" and handling it by the seance and presence objects instead of seanceId