import 'school.dart'; import 'package:refilc/utils/format.dart'; class Student { Map? json; String id; String name; School school; DateTime birth; String yearId; String? address; String? groupId; List parents; int gradeDelay; String? bankAccount; // List parentsPhone; String? className; Student({ required this.id, required this.name, required this.school, required this.birth, required this.yearId, this.address, required this.parents, required this.gradeDelay, this.bankAccount, // required this.parentsPhone, this.json, }); factory Student.fromJson(Map json) { List parents = []; parents = ((json["Gondviselok"] ?? []) as List) .cast() .map((e) => e["Nev"] ?? "") .toList() .cast(); if (json["AnyjaNeve"] != null) parents.insert(0, json["AnyjaNeve"]); parents = parents.map((e) => e.capitalize()).toList(); // fix name casing parents = parents.toSet().toList(); // remove duplicates return Student( id: json["Uid"] ?? "", name: (json["Nev"] ?? json["SzuletesiNev"] ?? "").trim(), school: School( instituteCode: json["IntezmenyAzonosito"] ?? "", name: json["IntezmenyNev"] ?? "", city: "", ), birth: json["SzuletesiDatum"] != null ? DateTime.parse(json["SzuletesiDatum"]).toLocal() : DateTime(0), yearId: json["TanevUid"] ?? "", address: json["Cimek"] != null ? json["Cimek"].length > 0 ? json["Cimek"][0] : null : null, parents: parents, gradeDelay: json["Intezmeny"]["TestreszabasBeallitasok"] ["ErtekelesekMegjelenitesenekKesleltetesenekMerteke"] ?? 0, bankAccount: json["Bankszamla"]["BankszamlaSzam"], json: json, ); } }