import 'package:cheminova/controller/product_mannual_service.dart'; import 'package:cheminova/controller/product_stock_service.dart'; import 'package:cheminova/models/product_stock_model.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../models/product_mannual_model.dart'; // Your model import // Your service import class ProductStockController extends GetxController { var productStockList = [].obs; // Service to fetch data final ProductStockService productStockService = ProductStockService(); // Loading state var isLoading = false.obs; // Method to fetch product manuals from the service FuturefetchProductStock() async { try { // Set loading to true isLoading.value = true; SharedPreferences prefs = await SharedPreferences.getInstance(); String? token = prefs.getString('token'); var manuals = await productStockService.getProductStock(token!); // If data is returned, update the list if (manuals != null) { productStockList.value = manuals; } else { productStockList.value = []; // If no data, set an empty list } } catch (e) { // Handle error here, for example logging or showing an error message print("Error fetching product stock: $e"); } finally { // Set loading to false isLoading.value = false; } } @override void onInit() { // Fetch product manuals when the controller is initialized fetchProductStock(); super.onInit(); } }