From 3bfbe1793d5b9d0d75b724258e93fa9c3f2a1c35 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sat, 20 Jul 2024 22:46:01 +0300 Subject: [PATCH] 7/20/2 --- lib/controller/functions/crud.dart | 4 +++ lib/controller/functions/gemeni.dart | 45 ++++++++++++++++---------- lib/controller/local/translations.dart | 4 +++ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/controller/functions/crud.dart b/lib/controller/functions/crud.dart index 442fac8..d81ad37 100644 --- a/lib/controller/functions/crud.dart +++ b/lib/controller/functions/crud.dart @@ -7,6 +7,7 @@ import 'package:http/http.dart' as http; import 'package:SEFER/env/env.dart'; import '../../constant/api_key.dart'; +import '../../print.dart'; import 'gemeni.dart'; import 'upload_image.dart'; @@ -218,6 +219,9 @@ class CRUD { 'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}', }, ); + Log.print('response: ${response.request}'); + Log.print('response: ${response.body}'); + Log.print('response: ${payload}'); var jsonData = jsonDecode(response.body); if (response.statusCode == 200) { if (jsonData['status'] == 'success') { diff --git a/lib/controller/functions/gemeni.dart b/lib/controller/functions/gemeni.dart index 257f583..90ae2dc 100644 --- a/lib/controller/functions/gemeni.dart +++ b/lib/controller/functions/gemeni.dart @@ -304,25 +304,36 @@ class AI extends GetxController { responseIdEgyptDriverLicense['employmentType']?.toString() ?? 'Not specified', }; - var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload); - var status1 = jsonDecode(res); - isLoading = false; - update(); - // Handle response - if (status1['status'] == 'success') { - isDriverSaved = true; - Get.snackbar('Success', 'Driver data saved successfully', - backgroundColor: AppColor.greenColor); - } else { - Get.snackbar('Error', 'Failed to save driver data', + + try { + var res = await CRUD().post(link: AppLink.signUpCaptin, payload: payload); + + // Check if response is valid JSON + var status1; + try { + status1 = jsonDecode(res); + } catch (e) { + throw FormatException("Invalid JSON response: $res"); + } + + isLoading = false; + update(); + + if (status1['status'] == 'success') { + isDriverSaved = true; + Get.snackbar('Success', 'Driver data saved successfully', + backgroundColor: AppColor.greenColor); + } else { + Get.snackbar('Error'.tr, + '${'Failed to save driver data'.tr}: ${status1['message']}', + backgroundColor: Colors.red); + } + } catch (e) { + isLoading = false; + update(); + Get.snackbar('Error'.tr, 'An error occurred while saving driver data'.tr, backgroundColor: Colors.red); } - // } catch (e) { - // isLoading = false; - // update(); - // Get.snackbar('Error', 'An error occurred while saving driver data: $e', - // backgroundColor: Colors.red); - // } } addCriminalDeocuments() async { diff --git a/lib/controller/local/translations.dart b/lib/controller/local/translations.dart index 6d95685..696f874 100644 --- a/lib/controller/local/translations.dart +++ b/lib/controller/local/translations.dart @@ -6,9 +6,13 @@ class MyTranslation extends Translations { "ar": { 'ID Mismatch': "عدم تطابق الرقم التعريفي", "face detect": "كشف الوجه", + 'An error occurred while saving driver data': + "حدث خطأ أثناء حفظ بيانات السائق", "Face Detection Result": "نتيجة كشف الوجه", "false": "خطأ", "true": "صحيح", + 'Failed to save driver data': 'فشل حفظ بيانات السائق', + "similar": "مشابه", "not similar": "غير مشابه", "error": "خطأ",