site deparment dropdown added for create traf request
parent
2c7a8d035c
commit
450cb91268
@ -0,0 +1,62 @@
|
|||||||
|
import '../base.dart';
|
||||||
|
|
||||||
|
class TrafCustomer extends Base {
|
||||||
|
int? customerId;
|
||||||
|
int? langId;
|
||||||
|
String? nameValue;
|
||||||
|
String? customerName;
|
||||||
|
String? languageName;
|
||||||
|
int? id;
|
||||||
|
String? createdBy;
|
||||||
|
String? createdDate;
|
||||||
|
String? modifiedBy;
|
||||||
|
String? modifiedDate;
|
||||||
|
|
||||||
|
TrafCustomer({
|
||||||
|
this.customerId,
|
||||||
|
this.langId,
|
||||||
|
this.nameValue,
|
||||||
|
this.customerName,
|
||||||
|
this.languageName,
|
||||||
|
this.id,
|
||||||
|
this.createdBy,
|
||||||
|
this.createdDate,
|
||||||
|
this.modifiedBy,
|
||||||
|
this.modifiedDate,
|
||||||
|
}) : super(identifier: id?.toString() ?? '', name: nameValue ?? customerName);
|
||||||
|
|
||||||
|
factory TrafCustomer.fromJson(Map<String, dynamic> json) {
|
||||||
|
return TrafCustomer(
|
||||||
|
customerId: json['customerId'],
|
||||||
|
langId: json['langId'],
|
||||||
|
nameValue: json['nameValue'],
|
||||||
|
customerName: json['customerName'],
|
||||||
|
languageName: json['languageName'],
|
||||||
|
id: json['id'],
|
||||||
|
createdBy: json['createdBy'],
|
||||||
|
createdDate: json['createdDate'],
|
||||||
|
modifiedBy: json['modifiedBy'],
|
||||||
|
modifiedDate: json['modifiedDate'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'customerId': customerId,
|
||||||
|
'langId': langId,
|
||||||
|
'nameValue': nameValue,
|
||||||
|
'customerName': customerName,
|
||||||
|
'languageName': languageName,
|
||||||
|
'id': id,
|
||||||
|
'createdBy': createdBy,
|
||||||
|
'createdDate': createdDate,
|
||||||
|
'modifiedBy': modifiedBy,
|
||||||
|
'modifiedDate': modifiedDate,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return nameValue ?? customerName ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart';
|
||||||
|
import 'package:test_sa/models/new_models/traf_customer.dart';
|
||||||
|
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||||
|
|
||||||
|
import '../../controllers/api_routes/api_manager.dart';
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
loading = true;
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue