refactor: update routing and logic for steward features, including route imports and path adjustments

This commit is contained in:
2025-12-08 11:09:24 +03:30
parent 2f4edc1b6e
commit 890be0ded6
56 changed files with 519 additions and 305 deletions

View File

@@ -0,0 +1,309 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/broadcast_price/broadcast_price.dart';
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
import 'package:rasadyar_chicken/data/models/response/steward_remain_weight/steward_remain_weight.dart';
import 'package:rasadyar_chicken/features/steward/presentation/pages/root/logic.dart';
import 'package:rasadyar_chicken/presentation/utils/utils.dart';
import 'package:rasadyar_core/core.dart';
class SegmentationLogic extends GetxController {
StewardRootLogic rootLogic = Get.find<StewardRootLogic>();
RxBool isLoadingMoreAllocationsMade = false.obs;
RxInt currentPage = 1.obs;
late List<String> routesName;
RxInt selectedSegmentIndex = 0.obs;
RxBool isExpanded = false.obs;
RxInt expandedListIndex = (-1).obs;
Rx<Jalali> fromDateFilter = Jalali.now().obs;
Rx<Jalali> toDateFilter = Jalali.now().obs;
RxnString searchedValue = RxnString();
RxInt segmentType = 1.obs;
RxInt priceType = 2.obs;
RxInt quotaType = 2.obs;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
TextEditingController weightController = TextEditingController(text: '0');
RxBool isSubmitButtonEnabled = false.obs;
Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>();
Rxn<ProductModel> selectedProduct = Rxn<ProductModel>();
Rxn<SegmentationModel> selectedSegment = Rxn<SegmentationModel>();
Rxn<BroadcastPrice> broadcastPrice = Rxn<BroadcastPrice>();
Rx<Resource<PaginationModel<SegmentationModel>>> segmentationList =
Resource<PaginationModel<SegmentationModel>>.loading().obs;
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
Rx<Jalali> saleDate = Jalali.now().obs;
RxInt weight = 0.obs;
Rxn<Jalali> productionDate = Rxn(null);
Rxn<int> remainingStock = Rxn(null);
Map<String, DayData> freeProductionDateData = {};
Map<String, DayData> governmentalProductionDateData = {};
@override
void onInit() {
super.onInit();
routesName = ['قطعه‌بندی'].toList();
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
getAllSegmentation();
getGuilds();
ever(quotaType, (_) {
remainingStock.value = null;
productionDate.value = null;
});
_updateGovernmentalProductionDateData();
_updateFreeProductionDateData();
ever(rootLogic.stewardRemainWeight, (callback) {
_updateGovernmentalProductionDateData();
_updateFreeProductionDateData();
});
}
void _updateGovernmentalProductionDateData() {
List<RemainWeightDay> dates = rootLogic.stewardRemainWeight.value?.governmental ?? [];
governmentalProductionDateData = {
for (var element in dates)
element.day.toString().toJalali.formatCompactDate(): DayData(
value: element.amount?.toInt(),
),
};
}
void _updateFreeProductionDateData() {
var dates = rootLogic.stewardRemainWeight.value?.free ?? [];
freeProductionDateData = {
for (var element in dates)
element.day.toString().toJalali.formatCompactDate(): DayData(
value: element.amount?.toInt(),
),
};
}
@override
void onReady() {
super.onReady();
setUpListener();
}
void setSearchValue(String? value) {
searchedValue.value = value?.trim();
}
void setUpListener() {
debounce(
searchedValue,
(callback) => getAllSegmentation(),
time: Duration(milliseconds: timeDebounce),
);
everAll([selectedSegment, quotaType, priceType], (_) {
validateForm();
});
weightController.addListener(() => validateForm());
}
void setEditData(SegmentationModel item) {
selectedSegment.value = item;
weightController.text = item.weight.toString();
}
void clearForm() {
weightController.text = '0';
selectedSegment.value = null;
selectedGuildModel.value = null;
productionDate.value = null;
segmentType.value = 1;
priceType.value = 2;
quotaType.value = 1;
remainingStock.value = null;
}
void validateForm() {
var weight = int.tryParse(weightController.text.trim().clearComma) ?? 0;
var hasWeight = (remainingStock.value ?? 0) > weight;
isSubmitButtonEnabled.value =
selectedProduct.value != null &&
weightController.text.isNotEmpty &&
hasWeight &&
productionDate.value != null &&
weight > 0 &&
(segmentType.value == 1 || (segmentType.value == 2 && selectedGuildModel.value != null));
}
Future<void> getAllSegmentation([bool isLoadingMore = false]) async {
if (isLoadingMore) {
isLoadingMoreAllocationsMade.value = true;
} else {
segmentationList.value = Resource<PaginationModel<SegmentationModel>>.loading();
}
if (searchedValue.value != null &&
searchedValue.value!.trim().isNotEmpty &&
currentPage.value > 1) {
currentPage.value = 1; // Reset to first page if search value is set
}
await safeCall(
showError: true,
call: () async => await rootLogic.chickenRepository.getSegmentation(
token: rootLogic.tokenService.accessToken.value!,
queryParameters: buildQueryParams(
pageSize: 20,
page: currentPage.value,
search: 'filter',
role: 'Steward',
value: searchedValue.value,
fromDate: fromDateFilter.value.toDateTime(),
toDate: toDateFilter.value.toDateTime(),
),
),
onSuccess: (result) {
if ((result?.count ?? 0) == 0) {
segmentationList.value = Resource<PaginationModel<SegmentationModel>>.empty();
} else {
segmentationList.value = Resource<PaginationModel<SegmentationModel>>.success(
PaginationModel<SegmentationModel>(
count: result?.count ?? 0,
next: result?.next,
previous: result?.previous,
results: [
...(segmentationList.value.data?.results ?? []),
...(result?.results ?? []),
],
),
);
isLoadingMoreAllocationsMade.value = false;
}
},
);
}
Future<void> deleteSegmentation(String key) async {
await safeCall(
showError: true,
showSuccess: true,
call: () => rootLogic.chickenRepository.deleteSegmentation(
token: rootLogic.tokenService.accessToken.value!,
key: key,
),
);
}
Future<bool> editSegment() async {
var res = true;
safeCall(
showError: true,
call: () async => await rootLogic.chickenRepository.editSegmentation(
token: rootLogic.tokenService.accessToken.value!,
model: SegmentationModel(
key: selectedSegment.value?.key,
weight: int.tryParse(weightController.text.clearComma) ?? 0,
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
),
),
onSuccess: (result) {
res = true;
onRefresh();
},
onError: (error, stacktrace) {
res = false;
},
);
return res;
}
Future<bool> createSegment() async {
var res = true;
SegmentationModel segmentationModel = SegmentationModel(
productKey: selectedProduct.value?.key,
weight: int.tryParse(weightController.text.clearComma) ?? 0,
saleType: priceType.value == 1 ? 'governmental' : 'free',
quota: quotaType.value == 1 ? 'governmental' : 'free',
);
if (segmentType.value == 2) {
segmentationModel = segmentationModel.copyWith(guildKey: selectedGuildModel.value?.key);
}
segmentationModel = segmentationModel.copyWith(
productionDate: productionDate.value?.toDateTime().formattedDashedGregorian,
);
await safeCall(
showError: true,
call: () async => await rootLogic.chickenRepository.createSegmentation(
token: rootLogic.tokenService.accessToken.value!,
model: segmentationModel,
),
onSuccess: (result) async {
res = true;
isSubmitButtonEnabled.value = false;
onRefresh();
Future.delayed(
Duration(seconds: 1),
() => defaultShowSuccessMessage("قطعه‌بندی با موفقیت ثبت شد!"),
);
Get.back();
},
onError: (error, stacktrace) {
res = false;
},
);
return res;
}
Future<void> getGuilds() async {
safeCall(
call: () async => await rootLogic.chickenRepository.getGuilds(
token: rootLogic.tokenService.accessToken.value!,
queryParameters: buildQueryParams(queryParams: {'all': true}, role: 'Steward'),
),
onSuccess: (result) {
if (result != null) {
guildsModel.clear();
guildsModel.addAll(result);
}
},
onError: (error, stacktrace) {},
);
}
Future<void> onRefresh() async {
toggleExpansion();
currentPage.value = 1;
await rootLogic.onRefresh();
await getAllSegmentation();
await getBroadcastPrice();
_updateFreeProductionDateData();
_updateGovernmentalProductionDateData();
}
Future<void> getBroadcastPrice() async {
safeCall(
call: () async => await rootLogic.chickenRepository.getBroadcastPrice(
token: rootLogic.tokenService.accessToken.value!,
),
onSuccess: (result) {
broadcastPrice.value = result;
if (broadcastPrice.value?.active == true) {
priceType.value = 2;
}
},
onError: (error, stacktrace) {},
);
}
void toggleExpansion({int? index}) {
if (expandedListIndex.value == index || index == null) {
expandedListIndex.value = -1;
} else {
expandedListIndex.value = index;
}
}
}

View File

@@ -0,0 +1,285 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
import 'package:rasadyar_chicken/features/steward/presentation/pages/segmentation/widgets/cu_bottom_sheet.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
import 'package:rasadyar_chicken/presentation/widget/filter_bottom_sheet.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart';
class SegmentationPage extends GetView<SegmentationLogic> {
final today = Jalali.now();
final oneDayAgo = Jalali.now().addDays(-1);
final twoDaysAgo = Jalali.now().addDays(-2);
@override
Widget build(BuildContext context) {
return ChickenBasePage(
routes: controller.routesName,
onSearchChanged: (data) => controller.setSearchValue(data),
onFilterTap: () {
Get.bottomSheet(filterBottomSheet());
},
onRefresh: controller.onRefresh,
hasBack: false,
child: Stack(
children: [
Positioned.fill(
child: ObxValue((data) {
return RPaginatedListView(
onLoadMore: () async => controller.getAllSegmentation(true),
hasMore: data.value.data?.next != null,
listType: ListType.separated,
resource: data.value,
padding: EdgeInsets.fromLTRB(8, 8, 8, 80),
itemBuilder: (context, index) {
var item = data.value.data!.results![index];
return ObxValue((val) {
return ExpandableListItem2(
selected: val.value == index,
onTap: () => controller.toggleExpansion(index: index),
index: index,
child: itemListWidget(item),
secondChild: itemListExpandedWidget(item, index),
labelColor: AppColor.blueLight,
labelIconColor: AppColor.customGrey,
labelIcon: Assets.vec.convertCubeSvg.path,
);
}, controller.expandedListIndex);
},
itemCount: data.value.data?.results?.length ?? 0,
separatorBuilder: (context, index) => SizedBox(height: 8.h),
);
}, controller.segmentationList),
),
Positioned(
right: 10,
bottom: 90.h,
child: RFab.add(
onPressed: () {
Get.bottomSheet(
addOrEditBottomSheet(controller),
isScrollControlled: true,
ignoreSafeArea: false,
).whenComplete(() {
controller.clearForm();
//defaultShowSuccessMessage('با موفقیت ثبت شد');
});
},
),
),
],
),
);
}
Widget filterBottomSheet() => filterBottomSheetWidget(
fromDate: controller.fromDateFilter,
onChangedFromDate: (jalali) => controller.fromDateFilter.value = jalali,
toDate: controller.toDateFilter,
onChangedToDate: (jalali) => controller.toDateFilter.value = jalali,
onSubmit: () => controller.getAllSegmentation(),
);
Row itemListWidget(SegmentationModel item) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(width: 12),
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 4,
children: [
Text(
item.toGuild != null ? 'قطعه‌بند' : 'مباشر',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
Text(
item.date?.formattedJalaliDate ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.bgDark),
),
],
),
),
SizedBox(width: 4),
Expanded(
flex: 5,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
item.toGuild != null
? item.toGuild?.user?.fullname ?? 'N/A'
: item.buyer?.fullname ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
SizedBox(height: 2),
Text(
item.toGuild != null
? item.toGuild?.guildsName ?? 'N/A'
: item.buyer?.shop ?? 'N/A',
textAlign: TextAlign.center,
style: AppFonts.yekan14.copyWith(color: AppColor.bgDark),
),
],
),
),
SizedBox(width: 4),
Expanded(
flex: 2,
child: Column(
spacing: 4,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
item.weight.separatedByCommaFa.addKg,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
style: AppFonts.yekan14Bold.copyWith(color: AppColor.blueNormal),
),
Text(
item.saleType == "governmental" ? 'دولتی' : 'آزاد',
textAlign: TextAlign.center,
textDirection: TextDirection.ltr,
style: AppFonts.yekan14Bold.copyWith(
color: item.saleType == "governmental"
? AppColor.blueNormal
: AppColor.greenNormal,
),
),
],
),
),
],
);
}
Container itemListExpandedWidget(SegmentationModel item, int index) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
child: Column(
spacing: 8,
children: [
Container(
height: 32,
padding: EdgeInsets.symmetric(horizontal: 8),
decoration: ShapeDecoration(
color: AppColor.blueLight,
shape: RoundedRectangleBorder(
side: BorderSide(width: 1, color: AppColor.blueLightHover),
borderRadius: BorderRadius.circular(8),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
spacing: 3,
children: [
Text(
DateTimeExtensions(item.date)?.toJalali().formatter.wN ?? 'N/A',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.d} ${DateTimeExtensions(item.date)?.toJalali().formatter.mN ?? 'N/A'}',
style: AppFonts.yekan14.copyWith(color: AppColor.blueNormal),
),
],
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.y}',
style: AppFonts.yekan20.copyWith(color: AppColor.textColor),
),
Text(
'${DateTimeExtensions(item.date)?.toJalali().formatter.tHH}:${DateTimeExtensions(item.date)?.toJalali().formatter.tMM ?? 'N/A'}',
style: AppFonts.yekan14.copyWith(color: AppColor.textColor),
),
],
),
),
buildRow(
title: 'مشخصات خریدار',
value: item.toGuild != null
? item.toGuild?.user?.fullname ?? 'N/A'
: item.buyer?.fullname ?? 'N/A',
),
buildRow(
title: 'تلفن خریدار',
value: item.toGuild != null
? item.toGuild?.user?.mobile ?? 'N/A'
: item.buyer?.mobile ?? 'N/A',
),
buildRow(
title: 'نام واحد',
value: item.toGuild != null
? item.toGuild?.guildsName ?? 'N/A'
: item.buyer?.shop ?? 'N/A',
),
buildRow(title: 'ماهیت', value: item.toGuild != null ? 'قطعه‌بند' : 'مباشر'),
buildRow(title: 'نوع فروش', value: item.saleType == "governmental" ? 'دولتی' : 'آزاد'),
buildRow(title: 'انبار فروش', value: item.quota == "governmental" ? 'دولتی' : 'آزاد'),
buildRow(
title: 'تاریخ تولید گوشت',
value: item.productionDate?.toJalali.formatCompactDate() ?? 'ندارد',
),
buildRow(
title: 'وزن قطعه‌بندی',
value: item.weight!.separatedByCommaFa,
valueLabel: 'کیلوگرم',
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 16.w,
children: [
RElevated(
text: 'ویرایش',
width: 150.w,
height: 40.h,
onPressed: () {
controller.setEditData(item);
Get.bottomSheet(
addOrEditBottomSheet(controller, isOnEdit: true),
isScrollControlled: true,
ignoreSafeArea: false,
).whenComplete(() {
controller.clearForm();
});
},
textStyle: AppFonts.yekan20.copyWith(color: Colors.white),
backgroundColor: AppColor.greenNormal,
),
ROutlinedElevated(
text: 'حذف',
textStyle: AppFonts.yekan20.copyWith(color: AppColor.redNormal),
width: 150.w,
height: 40.h,
onPressed: () {
buildDeleteDialog(
onConfirm: () async {
controller.toggleExpansion();
controller.deleteSegmentation(item.key!);
},
onRefresh: () => controller.onRefresh(),
);
},
borderColor: AppColor.redNormal,
),
],
),
],
),
);
}
}

View File

@@ -0,0 +1,395 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/features/steward/presentation/pages/segmentation/logic.dart';
import 'package:rasadyar_core/core.dart';
Widget addOrEditBottomSheet(SegmentationLogic controller, {bool isOnEdit = false}) {
return BaseBottomSheet(
height: isOnEdit ? 350.h : 600.h,
child: SingleChildScrollView(
child: Form(
key: controller.formKey,
child: Column(
spacing: 16,
children: [
Text(
isOnEdit ? 'ویرایش قطعه‌بندی' : 'افزودن قطعه‌بندی',
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
),
_productDropDown(controller),
Visibility(
visible: isOnEdit == false,
child: Container(
height: 50.h,
clipBehavior: Clip.none,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Positioned(
child: Container(color: Colors.white, child: Text("انبار")),
top: -10,
right: 8,
),
Obx(() {
return RadioGroup(
groupValue: controller.quotaType.value,
onChanged: (value) {
controller.quotaType.value = value ?? 0;
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: GestureDetector(
onTap: () {
controller.quotaType.value = 1;
},
child: Row(
children: [
Radio(value: 1),
Text('دولتی', style: AppFonts.yekan14),
],
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
controller.quotaType.value = 2;
},
child: Row(
children: [
Radio(value: 2),
Text('آزاد', style: AppFonts.yekan14),
],
),
),
),
],
),
);
}),
],
),
),
),
Obx(() {
return MonthlyDataCalendar(
label: 'تاریخ تولید گوشت',
selectedDate: controller.productionDate.value?.formatCompactDate(),
onDateSelect: (value) {
controller.productionDate.value = value.date;
controller.remainingStock.value = value.remainingStock;
},
dayData: controller.quotaType.value == 1
? controller.governmentalProductionDateData
: controller.freeProductionDateData,
);
}),
RTextField(
controller: controller.weightController,
keyboardType: TextInputType.number,
autoValidateMode: AutovalidateMode.onUserInteraction,
borderColor: AppColor.darkGreyLight,
filledColor: AppColor.bgLight,
filled: true,
inputFormatters: [FilteringTextInputFormatter.digitsOnly, SeparatorInputFormatter()],
validator: (value) {
if ((int.tryParse(value?.clearComma ?? '0') ?? 0) >
(controller.remainingStock.value ?? 0)) {
return 'وزن تخصیصی بیشتر از موجودی انبار است';
}
return null;
},
onChanged: (p0) {
controller.weight.value = int.tryParse(p0.clearComma) ?? 0;
},
label: 'وزن لاشه (کیلوگرم)',
),
Visibility(
visible: isOnEdit == false,
child: Container(
height: 58.h,
clipBehavior: Clip.none,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Stack(
fit: StackFit.expand,
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Positioned(
child: Container(color: Colors.white, child: Text("فروش")),
top: -10,
right: 8,
),
Obx(() {
return RadioGroup(
groupValue: controller.priceType.value,
onChanged: (value) {
controller.priceType.value = value!;
},
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: (controller.broadcastPrice.value?.active ?? false)
? () {
controller.priceType.value = 1;
}
: null,
child: Row(
children: [
Radio(
value: 1,
enabled: controller.broadcastPrice.value?.active ?? false,
),
Text(
'قیمت مصوب',
style: AppFonts.yekan14.copyWith(
color: (controller.broadcastPrice.value?.active ?? false)
? AppColor.textColor
: AppColor.labelTextColor,
),
),
],
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
controller.priceType.value = 2;
},
child: Row(
children: [
Radio(value: 2),
Text('قیمت آزاد', style: AppFonts.yekan14),
],
),
),
),
],
),
);
}),
],
),
),
),
Visibility(
visible: isOnEdit == false,
child: Column(
spacing: 12,
children: [
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColor.darkGreyLight, width: 1),
),
child: Column(
children: [
const SizedBox(height: 8),
SizedBox(
height: 40,
child: ObxValue((data) {
return RadioGroup(
onChanged: (value) {
controller.segmentType.value = value!;
controller.selectedGuildModel.value = null;
controller.selectedGuildModel.refresh();
},
groupValue: controller.segmentType.value,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Radio(value: 1),
Text('قطعه‌بندی(کاربر)', style: AppFonts.yekan14),
SizedBox(width: 12),
Radio(value: 2),
Text('تخصیص به قطعه‌بند', style: AppFonts.yekan14),
],
),
);
}, controller.priceType),
),
const SizedBox(height: 12),
ObxValue((data) {
return Visibility(
visible: data.value == 2,
child: guildsDropDown(controller),
);
}, controller.segmentType),
],
),
),
],
),
),
submitButtonWidget(controller, isOnEdit: isOnEdit),
SizedBox(),
],
),
),
),
);
}
Widget submitButtonWidget(SegmentationLogic controller, {bool isOnEdit = false}) {
return ObxValue((data) {
return RElevated(
isFullWidth: true,
backgroundColor: AppColor.greenNormal,
text: isOnEdit ? 'ویرایش' : 'ثبت',
onPressed: data.value
? () async {
var res = isOnEdit
? await controller.editSegment()
: await controller.createSegment();
if (res) {
Get.back();
}
}
: null,
height: 40,
);
}, controller.isSubmitButtonEnabled);
}
Widget _productDropDown(SegmentationLogic controller) {
return Obx(() {
return OverlayDropdownWidget<ProductModel>(
items: controller.rootLogic.rolesProductsModel,
height: 56,
hasDropIcon: false,
background: Colors.white,
onChanged: (value) {
controller.selectedProduct.value = value;
},
selectedItem: controller.selectedProduct.value,
initialValue: controller.selectedProduct.value,
itemBuilder: (item) => Text(item.name ?? 'بدون نام'),
labelBuilder: (item) => Row(
spacing: 8,
children: [
(item?.name?.contains('مرغ گرم') ?? false)
? Assets.images.chicken.image(width: 40, height: 40)
: Assets.vec.placeHolderSvg.svg(width: 40, height: 40),
Text(item?.name ?? 'انتخاب محصول'),
Spacer(),
ObxValue((data) {
return Visibility(visible: data.value != null, child: Text('موجودی: $data'));
}, controller.remainingStock),
],
),
);
});
}
Widget guildsDropDown(SegmentationLogic controller) {
return Obx(() {
final item = controller.selectedGuildModel.value;
return OverlayDropdownWidget<GuildModel>(
key: ValueKey(item?.user?.fullname ?? ''),
items: controller.guildsModel,
onChanged: (value) {
controller.selectedGuildModel.value = value;
},
selectedItem: item,
itemBuilder: (item) => Text(
item.user != null
? '${item.steward == true ? 'مباشر' : 'صنف'} ${item.user!.fullname} (${item.user!.mobile})'
: 'بدون نام',
),
labelBuilder: (item) => Text(
item?.user != null
? '${item?.steward == true ? 'مباشر' : 'صنف'} ${item?.user!.fullname} (${item?.user!.mobile})'
: 'انتخاب مباشر/صنف',
),
);
});
}
Container modalDatePicker(SegmentationLogic controller, ValueChanged<Jalali> onDateSelected) {
Jalali currentDate = Jalali.now();
Jalali? tempPickedDate;
return Container(
height: 250,
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Row(
children: [
SizedBox(width: 20),
RElevated(
height: 35,
width: 70,
textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
onPressed: () {
onDateSelected(tempPickedDate ?? Jalali.now());
Get.back();
},
text: 'تایید',
),
Spacer(),
RElevated(
height: 35,
width: 70,
backgroundColor: AppColor.error,
textStyle: AppFonts.yekan14.copyWith(color: Colors.white),
onPressed: () {
onDateSelected(tempPickedDate ?? Jalali.now());
Get.back();
},
text: 'لغو',
),
SizedBox(width: 20),
],
),
),
Divider(height: 0, thickness: 1),
Expanded(
child: Container(
child: PersianCupertinoDatePicker(
initialDateTime: controller.saleDate.value,
mode: PersianCupertinoDatePickerMode.date,
maximumDate: currentDate.addDays(3),
minimumDate: currentDate.toDateTime().subtract(Duration(days: 1)).toString().toJalali,
maximumYear: currentDate.year,
minimumYear: currentDate.year,
onDateTimeChanged: (dateTime) {
tempPickedDate = dateTime;
},
),
),
),
],
),
);
}