import 'dart:convert'; import 'dart:developer'; import 'dart:io'; import 'package:unit2/model/passo/additional_items.dart'; import 'package:http/http.dart' as http; import 'package:unit2/utils/request.dart'; import '../../../utils/urls.dart'; class AdditionalItemsServices { static final AdditionalItemsServices _instance = AdditionalItemsServices(); static AdditionalItemsServices get instance => _instance; String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKeySecret = "unitcYqAN7GGalyz"; Future> fetch(tempID) async { String path = Url.instance.additionalItems(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "bldgappr_details_id": tempID.toString(), }; try { http.Response response = await Request.instance .getRequest(param: params, path: path, headers: headers); if (response.statusCode == 200) { final List result = jsonDecode(response.body)['data']; print(result); return result.map(((e) => AdditionalItems.fromJson(e))).toList(); } else { throw Exception(response.reasonPhrase); } } catch (e) { throw e.toString(); } } Future add(AdditionalItems items) async { String path = Url.instance.additionalItems(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; http.Response? response; try { response = await Request.instance.postRequest( param: {}, path: path, body: items.toJson(), headers: headers); } catch (e) { log(e.toString()); } return response; } Future remove(id) async { String path = Url.instance.additionalItems(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', 'X-Client-Key': xClientKey, 'X-Client-Secret': xClientKeySecret }; Map params = { "id": id.toString(), }; try { http.Response response = await Request.instance .deleteRequest(path: path, headers: headers, body: {}, param: params); print(id); if (response.statusCode == 200) { print(response.body); return response; } else { throw Exception(response.reasonPhrase); } } catch (e) { throw e.toString(); } } }