feat : new segment logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rasadyar_auth/data/utils/safe_call.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/roles_products/roles_products.dart';
|
||||||
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
|
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
|
||||||
import 'package:rasadyar_chicken/presentation/pages/root/logic.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> fromDateFilter = Jalali.now().obs;
|
||||||
Rx<Jalali> toDateFilter = Jalali.now().obs;
|
Rx<Jalali> toDateFilter = Jalali.now().obs;
|
||||||
RxnString searchedValue = RxnString();
|
RxnString searchedValue = RxnString();
|
||||||
|
RxInt saleType = 1.obs;
|
||||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||||
TextEditingController weightController = TextEditingController(text: '0');
|
TextEditingController weightController = TextEditingController(text: '0');
|
||||||
RxBool isSubmitButtonEnabled = false.obs;
|
RxBool isSubmitButtonEnabled = false.obs;
|
||||||
|
Rxn<GuildModel> selectedGuildModel = Rxn<GuildModel>();
|
||||||
Rxn<ProductModel> selectedProduct = Rxn<ProductModel>();
|
Rxn<ProductModel> selectedProduct = Rxn<ProductModel>();
|
||||||
Rxn<SegmentationModel> selectedSegment = Rxn<SegmentationModel>();
|
Rxn<SegmentationModel> selectedSegment = Rxn<SegmentationModel>();
|
||||||
|
|
||||||
Rx<Resource<PaginationModel<SegmentationModel>>> segmentationList =
|
Rx<Resource<PaginationModel<SegmentationModel>>> segmentationList =
|
||||||
Resource<PaginationModel<SegmentationModel>>.loading().obs;
|
Resource<PaginationModel<SegmentationModel>>.loading().obs;
|
||||||
|
|
||||||
|
RxList<GuildModel> guildsModel = <GuildModel>[].obs;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
routesName = ['قطعهبندی'].toList();
|
routesName = ['قطعهبندی'].toList();
|
||||||
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
|
once(rootLogic.rolesProductsModel, (callback) => selectedProduct.value = callback.first);
|
||||||
getAllSegmentation();
|
getAllSegmentation();
|
||||||
|
getGuilds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -187,4 +192,25 @@ class SegmentationLogic extends GetxController {
|
|||||||
);
|
);
|
||||||
return res;
|
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/material.dart';
|
||||||
import 'package:flutter/services.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/roles_products/roles_products.dart';
|
||||||
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
|
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
|
||||||
import 'package:rasadyar_chicken/presentation/widget/base_page/view.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]) {
|
Widget addOrEditBottomSheet([bool isOnEdit = false]) {
|
||||||
return BaseBottomSheet(
|
return BaseBottomSheet(
|
||||||
height: 340.h,
|
height: 430.h,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Form(
|
child: Form(
|
||||||
key: controller.formKey,
|
key: controller.formKey,
|
||||||
@@ -240,7 +241,53 @@ class SegmentationPage extends GetView<SegmentationLogic> {
|
|||||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
||||||
),
|
),
|
||||||
_productDropDown(),
|
_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(
|
Container(
|
||||||
padding: EdgeInsets.all(8),
|
padding: EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
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 Widget Function(T? selected) labelBuilder;
|
||||||
final void Function(T selected)? onChanged;
|
final void Function(T selected)? onChanged;
|
||||||
final EdgeInsets? contentPadding;
|
final EdgeInsets? contentPadding;
|
||||||
|
final bool isDisabled;
|
||||||
const OverlayDropdownWidget({
|
const OverlayDropdownWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.items,
|
required this.items,
|
||||||
@@ -27,6 +27,7 @@ class OverlayDropdownWidget<T> extends StatefulWidget {
|
|||||||
this.height,
|
this.height,
|
||||||
this.background,
|
this.background,
|
||||||
this.hasDropIcon = true,
|
this.hasDropIcon = true,
|
||||||
|
this.isDisabled = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -123,9 +124,11 @@ class _OverlayDropdownState<T> extends State<OverlayDropdownWidget<T>> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
key: _key,
|
key: _key,
|
||||||
onTap: () {
|
onTap: widget.isDisabled
|
||||||
_isOpen.value ? _removeOverlay() : _showOverlay();
|
? null
|
||||||
},
|
: () {
|
||||||
|
_isOpen.value ? _removeOverlay() : _showOverlay();
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: widget.height?.toDouble() ?? 40,
|
height: widget.height?.toDouble() ?? 40,
|
||||||
width: Get.width,
|
width: Get.width,
|
||||||
|
|||||||
Reference in New Issue
Block a user