import 'package:get/get.dart'; import 'package:marco/helpers/services/api_service.dart'; import 'package:marco/model/service_project/service_projects_details_model.dart'; class ServiceProjectDetailsController extends GetxController { // Selected project id var projectId = ''.obs; // Project details var projectDetail = Rxn(); // Loading state var isLoading = false.obs; // Error message var errorMessage = ''.obs; /// Set project id and fetch its details void setProjectId(String id) { projectId.value = id; fetchProjectDetail(); } /// Fetch project detail from API Future fetchProjectDetail() async { if (projectId.value.isEmpty) { errorMessage.value = "Invalid project ID"; return; } isLoading.value = true; errorMessage.value = ''; try { final result = await ApiService.getServiceProjectDetailApi(projectId.value); if (result != null && result.data != null) { projectDetail.value = result.data!; } else { errorMessage.value = result?.message ?? "Failed to fetch project details"; } } catch (e) { errorMessage.value = "Error: $e"; } finally { isLoading.value = false; } } /// Refresh project details manually Future refresh() async { await fetchProjectDetail(); } }