fix : change product list in root

This commit is contained in:
2025-07-14 12:35:12 +03:30
parent ac75fc38c2
commit f79a3ae46f
8 changed files with 47 additions and 44 deletions

View File

@@ -22,10 +22,9 @@ class SegmentationLogic extends GetxController {
RxnString searchedValue = RxnString();
GlobalKey<FormState> formKey = GlobalKey<FormState>();
TextEditingController weightController = TextEditingController();
RxBool isSaleSubmitButtonEnabled = false.obs;
TextEditingController weightController = TextEditingController(text: '0');
RxBool isSubmitButtonEnabled = false.obs;
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
Rxn<ProductModel> selectedProduct = Rxn<ProductModel>();
Rxn<SegmentationModel> selectedSegment = Rxn<SegmentationModel>();
@@ -36,6 +35,7 @@ class SegmentationLogic extends GetxController {
void onInit() {
super.onInit();
routesName = ['قطعه‌بندی'].toList();
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
getAllSegmentation();
}
@@ -61,6 +61,11 @@ class SegmentationLogic extends GetxController {
(callback) => getAllSegmentation(),
time: Duration(milliseconds: timeDebounce),
);
ever(selectedSegment, (_) {
validateForm();
});
weightController.addListener(() => validateForm());
}
void setEditData(SegmentationModel item) {
@@ -69,13 +74,23 @@ class SegmentationLogic extends GetxController {
}
void clearForm() {
weightController.clear();
isSaleSubmitButtonEnabled.value = false;
weightController.text = '0';
isSubmitButtonEnabled.value = false;
selectedProduct.value = null;
selectedSegment.value = null;
formKey.currentState?.reset();
}
void validateForm() {
isSubmitButtonEnabled = RxBool(
selectedProduct.value != null &&
selectedSegment.value != null &&
weightController.text.isNotEmpty &&
int.tryParse(weightController.text) != null &&
int.tryParse(weightController.text)! > 0,
);
}
Future<void> getAllSegmentation([bool isLoadingMore = false]) async {
if (isLoadingMore) {
isLoadingMoreAllocationsMade.value = true;
@@ -134,22 +149,6 @@ class SegmentationLogic extends GetxController {
);
}
Future<void> getRolesProducts() async {
safeCall(
call: () async => await rootLogic.chickenRepository.getRolesProducts(
token: rootLogic.tokenService.accessToken.value!,
),
onSuccess: (result) {
if (result != null) {
rolesProductsModel.value = result;
selectedProduct.value = rolesProductsModel.first;
}
},
onError: (error, stacktrace) {},
);
}
Future<bool> editSegment() async {
var res = true;
safeCall(