import 'dart:convert'; import 'dart:developer'; import 'dart:io'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:unit2/model/passo/property_appraisal.dart'; import 'package:http/http.dart' as http; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; import '../../../model/passo/property_appraisal_edit.dart'; class PropertyAppraisalServices { static final PropertyAppraisalServices _instance = PropertyAppraisalServices(); static PropertyAppraisalServices get instance => _instance; String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKeySecret = "unitcYqAN7GGalyz"; Future fetch() async { final tempID = await SharedPreferences.getInstance(); print('sds'); print(tempID.getInt('tempid')! - 1); final id = tempID.getInt('tempid')! - 1; String path = Url.instance.propertyAppraisal(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "bldgappr_details_id": id.toString(), }; try { http.Response response = await Request.instance .getRequest(param: params, path: path, headers: headers); print('Appraisal TEMPID'); print(response.body); if (response.statusCode == 200) { final jsonData = jsonDecode(response.body); final dataList = jsonData['data'] as List; final result = PropertyAppraisal.fromJson(dataList[0] as Map); return result; } else { throw Exception(response.reasonPhrase); } } catch (e) { throw e.toString(); } } Future update(PropertyAppraisal appraisal, tempID) async { String path = Url.instance.propertyAppraisal(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "bldgappr_details_id": tempID.toString(), }; print(tempID); http.Response? response; try { response = await Request.instance.putRequest( path: path, body: appraisal.toJson(), headers: headers, param: params); } catch (e) { log(e.toString()); } return response; } Future fetchEdit(id) async { String path = Url.instance.propertyAppraisal(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "bldgappr_details_id": id.toString(), }; try { http.Response response = await Request.instance .getRequest(param: params, path: path, headers: headers); print('Property_Apraisaledit'); print(response.body); if (response.statusCode == 200) { final jsonData = jsonDecode(response.body); final dataList = jsonData['data'] as List; final result = PropertyAppraisalEdit.fromJson(dataList[0] as Map); return result; } else { throw Exception(response.reasonPhrase); } } catch (e) { throw e.toString(); } } Future updateAppraisal( PropertyAppraisalEdit appraisal, tempID) async { String path = Url.instance.propertyAppraisal(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "bldgappr_details_id": tempID, }; print(tempID); http.Response? response; try { response = await Request.instance.putRequest( path: path, body: appraisal.toJson(), headers: headers, param: params); } catch (e) { log(e.toString()); } return response; } }