rd-android-app/lib/controller/product_mannual_controller.dart
saritabirare 545637e035 1)product manual api integration
2)order management implementation
2024-09-16 16:48:52 +05:30

48 lines
1.4 KiB
Dart

import 'package:cheminova/controller/product_mannual_service.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 ProductManualController extends GetxController {
var productManualList = <ProductManualModel>[].obs;
// Service to fetch data
final ProductMannualService productMannualService = ProductMannualService();
// Loading state
var isLoading = false.obs;
// Method to fetch product manuals from the service
void fetchProductManuals() async {
try {
// Set loading to true
isLoading.value = true;
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
var manuals = await productMannualService.getProductManuals(token!);
// If data is returned, update the list
if (manuals != null) {
productManualList.value = manuals;
} else {
productManualList.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 manuals: $e");
} finally {
// Set loading to false
isLoading.value = false;
}
}
@override
void onInit() {
// Fetch product manuals when the controller is initialized
fetchProductManuals();
super.onInit();
}
}