import 'dart:convert'; import 'package:unit2/model/location/country.dart'; import 'package:http/http.dart' as http; import 'package:unit2/model/location/region.dart'; import 'package:unit2/model/utils/eligibility.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; import '../model/profile/basic_information/contact_information.dart'; import '../model/utils/agency.dart'; import '../model/utils/category.dart'; import '../model/utils/position.dart'; class ProfileUtilities { static final ProfileUtilities _instance = ProfileUtilities(); static ProfileUtilities get instance => _instance; Future> getEligibilities() async { List eligibilities = []; String path = Url.instance.eligibilities(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; try { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var eligibility) { Eligibility newEligibilities = Eligibility.fromJson(eligibility); eligibilities.add(newEligibilities); }); } } } catch (e) { throw (e.toString()); } return eligibilities; } ////get agency position Future> getAgencyPosition() async { List agencyPositions = []; String path = Url.instance.getPositions(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; try { http.Response response = await Request.instance .getRequest(param: {}, path: path, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var agencyPosition) { Position position = Position.fromJson(agencyPosition); agencyPositions.add(position); }); } } } catch (e) { throw (e.toString()); } return agencyPositions; } ////get agencies Future> getAgecies() async { List agencies = []; String path = Url.instance.getAgencies(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; try { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var agency) { Agency newAgency = Agency.fromJson(agency); agencies.add(newAgency); }); } } } catch (e) { throw e.toString(); } return agencies; } ////get agency category Future> agencyCategory() async { List agencyCategory = []; String path = Url.instance.getAgencyCategory(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; try { http.Response response = await Request.instance .getRequest(param: {}, path: path, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); if (data['data'] != null) { data['data'].forEach((var agency) { Category category = Category.fromJson(agency); agencyCategory.add(category); }); } } } catch (e) { throw e.toString(); } return agencyCategory; } //// get service type Future> getServiceType() async { List serviceTypes = []; Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; String path = Url.instance.getServiceTypes(); try { http.Response response = await Request.instance .getRequest(param: {}, path: path, headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); if (data['data'] != null) { for (var element in data['data']) { ServiceType newServiceType = ServiceType.fromJson(element); serviceTypes.add(newServiceType); } } } } catch (e) { throw e.toString(); } return serviceTypes; } }