Update: 2026-06-26 17:29:23

This commit is contained in:
Hamza-Ayed
2026-06-26 17:29:23 +03:00
parent a323da29aa
commit 9ded734e38
139 changed files with 1815 additions and 2676 deletions

View File

@@ -1,34 +1,51 @@
import 'dart:convert';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../../views/widgets/snackbar.dart';
import '../functions/crud.dart';
class KazanController extends GetxController {
var kazanData = {}.obs;
var isLoading = false.obs;
var selectedCountry = 'Syria'.obs;
final CRUD _crud = CRUD();
final List<Map<String, String>> countries = [
{'code': 'syria', 'name': 'سوريا', 'flag': '🇸🇾'},
{'code': 'jordan', 'name': 'الأردن', 'flag': '🇯🇴'},
{'code': 'egypt', 'name': 'مصر', 'flag': '🇪🇬'},
];
@override
void onInit() {
super.onInit();
getKazan();
}
void setCountry(String countryName) {
selectedCountry.value = countryName;
getKazan();
}
Future<void> getKazan() async {
isLoading.value = true;
try {
var response = await _crud.get(link: "${AppLink.getKazanPercent}?country=syria");
final countryParam = selectedCountry.value.toLowerCase();
var response = await _crud.get(link: "${AppLink.getKazanPercent}?country=$countryParam");
if (response != null && response != 'failure' && response != 'token_expired') {
var decoded = response is String ? jsonDecode(response) : response;
if (decoded['status'] == "success") {
var message = decoded['message'];
if (message is List && message.isNotEmpty) {
kazanData.value = message[0];
kazanData.value = Map<String, dynamic>.from(message[0]);
kazanData['country'] = selectedCountry.value;
} else {
kazanData.value = {'country': selectedCountry.value};
}
}
}
} catch (e) {
Get.snackbar("خطأ", "فشل جلب بيانات التسعير: $e");
mySnackbarError('فشل جلب بيانات التسعير: $e');
} finally {
isLoading.value = false;
}
@@ -37,8 +54,9 @@ class KazanController extends GetxController {
Future<bool> updateKazan(Map<String, dynamic> data) async {
isLoading.value = true;
try {
data['country'] = selectedCountry.value;
final String link = data.containsKey('id') ? AppLink.updateKazanPercent : AppLink.addKazanPercent;
Map<String, String> payload = {};
data.forEach((key, value) {
payload[key] = value.toString();
@@ -51,7 +69,7 @@ class KazanController extends GetxController {
}
return false;
} catch (e) {
Get.snackbar("خطأ", "فشل تحديث التسعير: $e");
mySnackbarError('فشل تحديث التسعير: $e');
return false;
} finally {
isLoading.value = false;