import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:unit2/model/login_data/employee_info/employee_info.dart'; import 'package:unit2/model/profile/basic_info.dart'; import 'package:unit2/model/profile/basic_information/citizenship.dart'; import 'package:unit2/model/profile/basic_information/contact_information.dart'; import 'package:unit2/model/profile/basic_information/identification_information.dart'; import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/profileInfomation.dart'; import 'package:unit2/model/profile/references.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; import '../../model/profile/basic_information/primary-information.dart'; class ProfileService { static final ProfileService _instance = ProfileService(); static ProfileService get instance => _instance; Future getProfile(String token, int id) async { String url = Url.instance.profileInformation(); String path = url + id.toString(); ProfileInformation? profileInformation0; List references = []; ContactInfo contactInfo; Identification identification; List identificationInformation =[]; List contactInformation = []; PrimaryInformation primaryInformation; List eligibilities = []; List citizenships = []; List learningsDevelopments = []; Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': "Token $token" }; // try{ http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); // get primary information primaryInformation = PrimaryInformation.fromJson( data['data']['basic_information']['primary_information']); // get all contacts data['data']['basic_information']['contact_information'] .forEach((var contact) { contactInfo = ContactInfo.fromJson(contact['contact_info']); contactInformation.add(contactInfo); }); // get all identifications data['data']['basic_information']['identification_records'].forEach((var identity){ identification = Identification.fromJson(identity); identificationInformation.add(identification); }); //get all eligibilities data['data']['eligibilities'].forEach((var cert){ EligibityCert eligibility = EligibityCert.fromJson(cert); eligibilities.add(eligibility); }); // get all citizenships if(data['data']['citizenship']!= null){ data['data']['citizenships'].forEach((var citizenship){ Citizenship person = Citizenship.fromJson(citizenship); citizenships.add(person); }); } // get all references; data['data']['personal_references'].forEach((var person){ PersonalReference reference = PersonalReference.fromJson(person); references.add(reference); }); //get all learning and developments data['data']['learning_development'].forEach((var training){ LearningDevelopement learnings = LearningDevelopement.fromJson(training); learningsDevelopments.add(learnings); }); BasicInfo basicInfo = BasicInfo(contactInformation: contactInformation, primaryInformation: primaryInformation, identifications: identificationInformation, citizenships: citizenships ); ProfileInformation profileInformation = ProfileInformation(basicInfo: basicInfo,eligibilities: eligibilities,references: references!,learningsAndDevelopment: learningsDevelopments); profileInformation0 = profileInformation; } // }catch(e){ // throw(e.toString()); // } return profileInformation0; } }