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

@@ -59,7 +59,7 @@ class BuyOutOfProvinceLogic extends GetxController {
getStewardPurchaseOutOfProvince();
selectedProvince.listen((p0) => getCites());
selectedProduct.value = outOfTheProvinceLogic.rolesProductsModel.first;
selectedProduct.value = rootLogic.rolesProductsModel.first;
setupListeners();
debounce(
@@ -220,7 +220,7 @@ class BuyOutOfProvinceLogic extends GetxController {
carcassWeightController.text = item.weightOfCarcasses?.toInt().toString() ?? '';
selectedProvince.value = IranProvinceCityModel(name: item.province);
selectedCity.value = IranProvinceCityModel(name: item.city);
selectedProduct.value = outOfTheProvinceLogic.rolesProductsModel.firstWhere(
selectedProduct.value = rootLogic.rolesProductsModel.firstWhere(
(element) => element.key == item.product!.key,
);
isSubmitButtonEnabled.value = true;

View File

@@ -407,7 +407,7 @@ class BuyOutOfProvincePage extends GetView<BuyOutOfProvinceLogic> {
Widget _productDropDown() {
return Obx(() {
return OverlayDropdownWidget<ProductModel>(
items: controller.outOfTheProvinceLogic.rolesProductsModel,
items: controller.rootLogic.rolesProductsModel,
height: 56,
hasDropIcon: false,
background: Colors.white,

View File

@@ -6,6 +6,7 @@ import 'package:rasadyar_auth/data/utils/safe_call.dart';
import 'package:rasadyar_chicken/data/di/chicken_di.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository.dart';
import 'package:rasadyar_chicken/data/repositories/chicken_repository_imp.dart';
import 'package:rasadyar_chicken/presentation/pages/buy/view.dart';
@@ -24,7 +25,7 @@ class RootLogic extends GetxController {
List<Widget> pages = [BuyPage(), SalePage(), HomePage(), SegmentationPage(), ProfilePage()];
final defaultRoutes = <int, String>{0: ChickenRoutes.buy, 1: ChickenRoutes.sale};
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
late DioRemote dioRemote;
var tokenService = Get.find<TokenStorageService>();
@@ -58,6 +59,9 @@ class RootLogic extends GetxController {
if (inventoryModel.value == null) {
getInventory();
}
if (rolesProductsModel.isEmpty) {
getRolesProducts();
}
}
@override
@@ -129,4 +133,17 @@ class RootLogic extends GetxController {
provinces.clear();
}
}
Future<void> getRolesProducts() async {
safeCall(
call: () async =>
await chickenRepository.getRolesProducts(token: tokenService.accessToken.value!),
onSuccess: (result) {
if (result != null) {
rolesProductsModel.value = result;
}
},
onError: (error, stacktrace) {},
);
}
}

View File

@@ -9,7 +9,6 @@ import 'package:rasadyar_core/core.dart';
class SaleLogic extends GetxController {
Rxn<List<AllocatedMadeModel>?> allocatedMadeModel = Rxn<List<AllocatedMadeModel>?>();
RxList<ProductModel> rolesProductsModel = RxList<ProductModel>();
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
@@ -24,7 +23,7 @@ class SaleLogic extends GetxController {
void onReady() {
super.onReady();
getStewardDashBord();
getRolesProducts();
}
Future<void> getAllocatedMade() async {
@@ -83,19 +82,6 @@ class SaleLogic 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;
}
},
onError: (error, stacktrace) {},
);
}
Future<void> getGuilds() async {}

View File

@@ -56,7 +56,7 @@ class SalesOutOfProvinceSalesListLogic extends GetxController {
void onReady() {
super.onReady();
selectedProduct.value = saleLogic.rolesProductsModel.first;
selectedProduct.value = rootLogic.rolesProductsModel.first;
debounce(
searchedValue,
(callback) => getOutProvinceSales(),
@@ -140,7 +140,7 @@ class SalesOutOfProvinceSalesListLogic extends GetxController {
selectedBuyer.value = buyerLogic.buyerList.value.data?.results?.firstWhere(
(element) => element.key == item.buyer?.key,
);
selectedProduct.value = saleLogic.rolesProductsModel.first;
selectedProduct.value = rootLogic.rolesProductsModel.first;
key = item.key;
isSaleSubmitButtonEnabled.value = true;
}

View File

@@ -343,7 +343,7 @@ class SalesOutOfProvinceSalesListPage extends GetView<SalesOutOfProvinceSalesLis
Widget _productDropDown() {
return Obx(() {
return OverlayDropdownWidget<ProductModel>(
items: controller.saleLogic.rolesProductsModel,
items: controller.rootLogic.rolesProductsModel,
height: 56,
hasDropIcon: false,
background: Colors.white,

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(