feat : new segment logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_auth/data/utils/safe_call.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/presentation/pages/root/logic.dart';
|
||||
@@ -21,23 +22,27 @@ class SegmentationLogic extends GetxController {
|
||||
Rx<Jalali> fromDateFilter = Jalali.now().obs;
|
||||
Rx<Jalali> toDateFilter = Jalali.now().obs;
|
||||
RxnString searchedValue = RxnString();
|
||||
|
||||
RxInt saleType = 1.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>();
|
||||
|
||||
Rx<Resource<PaginationModel<SegmentationModel>>> segmentationList =
|
||||
Resource<PaginationModel<SegmentationModel>>.loading().obs;
|
||||
|
||||
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
routesName = ['قطعهبندی'].toList();
|
||||
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
|
||||
getAllSegmentation();
|
||||
getGuilds();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -187,4 +192,25 @@ class SegmentationLogic extends GetxController {
|
||||
);
|
||||
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) {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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/data/models/response/segmentation_model/segmentation_model.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
|
||||
@@ -228,7 +229,7 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
|
||||
Widget addOrEditBottomSheet([bool isOnEdit = false]) {
|
||||
return BaseBottomSheet(
|
||||
height: 340.h,
|
||||
height: 430.h,
|
||||
child: SingleChildScrollView(
|
||||
child: Form(
|
||||
key: controller.formKey,
|
||||
@@ -240,7 +241,53 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
||||
),
|
||||
_productDropDown(),
|
||||
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 Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Radio(
|
||||
value: 1,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
|
||||
controller.selectedGuildModel.value = null;
|
||||
controller.selectedGuildModel.refresh();
|
||||
},
|
||||
),
|
||||
Text('خودم', style: AppFonts.yekan14),
|
||||
SizedBox(width: 12),
|
||||
Radio(
|
||||
value: 2,
|
||||
groupValue: controller.saleType.value,
|
||||
onChanged: (value) {
|
||||
controller.saleType.value = value!;
|
||||
},
|
||||
),
|
||||
Text('صنف/مباشر', style: AppFonts.yekan14),
|
||||
],
|
||||
);
|
||||
}, controller.saleType),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
guildsDropDown(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
@@ -331,4 +378,30 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget guildsDropDown() {
|
||||
return Obx(() {
|
||||
final item = controller.selectedGuildModel.value;
|
||||
return OverlayDropdownWidget<GuildModel>(
|
||||
key: ValueKey(item?.user?.fullname ?? ''),
|
||||
items: controller.guildsModel,
|
||||
isDisabled: controller.saleType.value == 1,
|
||||
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})'
|
||||
: 'انتخاب مباشر/صنف',
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class OverlayDropdownWidget<T> extends StatefulWidget {
|
||||
final Widget Function(T? selected) labelBuilder;
|
||||
final void Function(T selected)? onChanged;
|
||||
final EdgeInsets? contentPadding;
|
||||
|
||||
final bool isDisabled;
|
||||
const OverlayDropdownWidget({
|
||||
super.key,
|
||||
required this.items,
|
||||
@@ -27,6 +27,7 @@ class OverlayDropdownWidget<T> extends StatefulWidget {
|
||||
this.height,
|
||||
this.background,
|
||||
this.hasDropIcon = true,
|
||||
this.isDisabled = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -123,9 +124,11 @@ class _OverlayDropdownState<T> extends State<OverlayDropdownWidget<T>> {
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
key: _key,
|
||||
onTap: () {
|
||||
_isOpen.value ? _removeOverlay() : _showOverlay();
|
||||
},
|
||||
onTap: widget.isDisabled
|
||||
? null
|
||||
: () {
|
||||
_isOpen.value ? _removeOverlay() : _showOverlay();
|
||||
},
|
||||
child: Container(
|
||||
height: widget.height?.toDouble() ?? 40,
|
||||
width: Get.width,
|
||||
|
||||
Reference in New Issue
Block a user