Student.fromJson constructor

Student.fromJson(
  1. Map<String, dynamic> json
)

Construit un étudiant à partir d’un objet JSON.

Implementation

factory Student.fromJson(Map<String, dynamic> json){
  Map<int, Choice> deserializedChoices = {};
  Student student = Student(
      json[jsonId],
      json[jsonName],
      deserializedChoices,
      json[jsonSpec],
      json[jsonRanking],
      json[jsonEcts],
      json[jsonLang_lvl],
      json[jsonMissedHours],
      json[jsonComment]);
  Map<String, dynamic> serializedChoices = json[jsonChoices];
  List<Choice> refusedChoices = [];
  for (var c in serializedChoices.entries){
    deserializedChoices[int.parse(c.key)] = Choice.fromJson(c.value, student);
  }
  for (var c in deserializedChoices.entries){
    deserializedChoices[c.key]?.student.choices[c.key] = deserializedChoices[c.key]!;
  }
  for (var rc in json[jsonRefused]){
    refusedChoices.add(Choice.fromJson(rc, student));
  }
  student.accepted = json[jsonAccepted] != "null" ? Choice.fromJson(json[jsonAccepted], student) : null;
  student.refused = refusedChoices;
  return student;
}