Update: 2026-06-26 17:36:57

This commit is contained in:
Hamza-Ayed
2026-06-26 17:36:57 +03:00
parent 9ded734e38
commit ae21389240
3 changed files with 24 additions and 18 deletions

View File

@@ -47,12 +47,13 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
setState(() => _isLoading = true);
try {
// إعداد الترويسة (Headers)
final headers = {
'Authorization':
'Bearer ${r(box.read(BoxName.jwt)).split(AppInformation.addd)[0]}',
'X-HMAC-Auth': '${box.read(BoxName.hmac)}',
};
final rawJwt = box.read(BoxName.jwt);
if (rawJwt == null) {
mySnackbarError('الرجاء تسجيل الدخول أولاً');
return;
}
final token = r(rawJwt.toString()).split(AppInformation.addd)[0];
final fingerprint = box.read(BoxName.fingerPrint) ?? '';
final uri = Uri.parse(AppLink.addInvoice);
final request = http.MultipartRequest('POST', uri)
@@ -60,9 +61,9 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
..fields['amount'] = amount
..fields['name'] = itemName
..fields['date'] = date
..headers.addAll(headers);
..headers['Authorization'] = 'Bearer $token'
..headers['X-Device-FP'] = fingerprint;
// إضافة الصورة إذا وجدت
if (_imageFile != null) {
final multipartFile = await http.MultipartFile.fromPath(
'image',
@@ -71,25 +72,24 @@ class _AddInvoicePageState extends State<AddInvoicePage> {
request.files.add(multipartFile);
}
final response = await request.send();
final respStr = await response.stream.bytesToString();
final streamed = await request.send();
final respStr = await streamed.stream.bytesToString();
// محاولة تحليل الاستجابة
Map<String, dynamic> data;
try {
data = jsonDecode(respStr);
} catch (e) {
data = {'status': 'error', 'message': 'Invalid server response'};
data = {
'status': 'error',
'message': 'خطأ في تحليل استجابة السيرفر: $respStr'
};
}
if (data['status'] == 'success') {
mySnackbarSuccess('تم حفظ الفاتورة بنجاح');
_itemNameController.clear();
_amountController.clear();
setState(() => _imageFile = null);
// تأخير بسيط قبل العودة لتحديث الصفحة السابقة
Future.delayed(const Duration(seconds: 1), () {
Get.back(result: true);
});