addLog function
Implementation
Future<void> addLog(TryOnProduct? product, TryOnProduct? previous) async {
try {
cityCountry = cityCountry ?? await getUserLocation();
} catch (e) {
try {
final value = await http.get(Uri.parse('http://ip-api.com/json'));
Map data = jsonDecode(value.body);
cityCountry = '${data['city']},${data['country']}';
} catch (err) {
cityCountry = 'Hydrabad, India';
}
}
var headers = {'Content-Type': 'application/json'};
var request = http.MultipartRequest(
'POST',
Uri.parse(
'${URLConstants.apiUrl}/${product?.productId ?? 'lastProduct'}/${product?.tryonType ?? previous?.productId ?? ''}/${product?.parentCategory}'));
request.fields.addAll({
'previuosProd': previous?.productId ?? 'firstProduct',
'city': cityCountry!.split(',').first,
'country': cityCountry!.split(',').last,
'browser': 'app',
'device': getDeviceType(),
'os': Platform.isIOS ? 'ios' : 'android',
});
request.headers.addAll(headers);
var res = await request.send();
String resStr = await res.stream.bytesToString();
}