passo_mobile_app/lib/sevices/passo/building/location_landref_services.dart

69 lines
2.0 KiB
Dart
Raw Normal View History

2023-07-28 02:35:36 +00:00
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:unit2/model/passo/bldg_loc.dart';
2023-09-01 03:22:48 +00:00
import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
2023-07-28 02:35:36 +00:00
class LocationLandrefServices {
static final LocationLandrefServices _instance = LocationLandrefServices();
static LocationLandrefServices get instance => _instance;
2023-09-01 03:22:48 +00:00
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz";
Future<http.Response?> update(BldgLoc data, id) async {
String path = Url.instance.bldgLocation();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map<String, String> params = {
"bldgappr_details_id": id.toString(),
};
2023-07-28 02:35:36 +00:00
http.Response? response;
try {
2023-09-01 03:22:48 +00:00
http.Response response = await Request.instance
.getRequest(param: params, path: path, headers: headers);
2023-07-28 02:35:36 +00:00
} catch (e) {
log(e.toString());
}
return response;
}
2023-09-01 03:22:48 +00:00
Future<BldgLoc> fetch(tempID) async {
String path = Url.instance.bldgLocation();
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Client-Key': xClientKey,
'X-Client-Secret': xClientKeySecret
};
Map<String, String> params = {
"bldgappr_details_id": tempID.toString(),
};
try {
http.Response response = await Request.instance
.getRequest(param: params, path: path, headers: headers);
print('BldgLocEdit');
print(response.body);
if (response.statusCode == 200) {
final jsonData = jsonDecode(response.body);
final dataList = jsonData['data'] as List<dynamic>;
final result = BldgLoc.fromJson(dataList[0] as Map<String, dynamic>);
return result;
} else {
print(response.reasonPhrase);
throw Exception(response.reasonPhrase);
}
} catch (e) {
throw e.toString();
}
}
2023-07-28 02:35:36 +00:00
}