|
|
|
|
@ -9,37 +9,8 @@ import '../../controllers/api_routes/urls.dart';
|
|
|
|
|
|
|
|
|
|
class CustomerLookupProvider extends LoadingListNotifier<TrafCustomer> {
|
|
|
|
|
@override
|
|
|
|
|
Future getData({int? id}) async {
|
|
|
|
|
if (loading == true) return -2;
|
|
|
|
|
loading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
try {
|
|
|
|
|
// Get customers by user ID (GUID string)
|
|
|
|
|
// If id is null, try to get it from the current user
|
|
|
|
|
String? userId = id?.toString();
|
|
|
|
|
|
|
|
|
|
Response response = await ApiManager.instance.get(
|
|
|
|
|
URLs.getCustomersByUserId + "?userId=$userId",
|
|
|
|
|
useCache: true,
|
|
|
|
|
enableToastMessage: false,
|
|
|
|
|
);
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
List categoriesListJson = json.decode(response.body)["data"];
|
|
|
|
|
items = categoriesListJson.map((item) => TrafCustomer.fromJson(item)).toList();
|
|
|
|
|
}
|
|
|
|
|
loading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return response.statusCode;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
loading = false;
|
|
|
|
|
stateCode = -1;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Future getData({int? id}) async {}
|
|
|
|
|
|
|
|
|
|
// Add method to get data by string user ID (GUID)
|
|
|
|
|
Future getDataByUserId(String? userId) async {
|
|
|
|
|
if (loading == true) return -2;
|
|
|
|
|
if (userId == null || userId.isEmpty) return -1;
|
|
|
|
|
@ -47,11 +18,7 @@ class CustomerLookupProvider extends LoadingListNotifier<TrafCustomer> {
|
|
|
|
|
loading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
try {
|
|
|
|
|
Response response = await ApiManager.instance.get(
|
|
|
|
|
URLs.getCustomersByUserId + "?userId=$userId",
|
|
|
|
|
useCache: true,
|
|
|
|
|
enableToastMessage: false,
|
|
|
|
|
);
|
|
|
|
|
Response response = await ApiManager.instance.get(URLs.getCustomersByUserId + "?userId=$userId", useCache: true, enableToastMessage: false);
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
List categoriesListJson = json.decode(response.body)["data"];
|
|
|
|
|
|