39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
import 'package:cheminova/models/get_invoice_model.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'get_single_invoice_Service.dart';
|
|
|
|
class GetSingleInvoiceController extends GetxController {
|
|
// Import your Invoice model file
|
|
|
|
// Observable for holding the fetched invoice
|
|
var invoice = <GetInvoiceModel?>[].obs;
|
|
var isLoading = true.obs; // Observable for loading state
|
|
var errorMessage = ''.obs; // Observable for error message
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
// Call fetchInvoice with a specific ID
|
|
}
|
|
|
|
Future<void> fetchInvoice(String invoiceId) async {
|
|
isLoading.value = true; // Set loading state to true
|
|
try {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
String? token = prefs.getString('token');
|
|
invoice.value = (await GetSingleInvoiceService().fetchInvoice(token!,invoiceId))
|
|
as List<GetInvoiceModel?>;
|
|
if (invoice.value == null) {
|
|
errorMessage.value = 'Invoice not found';
|
|
}
|
|
} catch (e) {
|
|
errorMessage.value = e.toString(); // Set the error message
|
|
} finally {
|
|
isLoading.value = false; // Set loading state to false
|
|
}
|
|
}
|
|
}
|