feat: refactor image handling in CreateInspectionBottomSheetLogic by replacing camera picker with RImagePicker for hall, input warehouse, and losses images, and add image listener setup for better state management
This commit is contained in:
@@ -190,21 +190,22 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
TextEditingController();
|
TextEditingController();
|
||||||
|
|
||||||
RxList<String> hallImagesUrls = RxList<String>();
|
RxList<String> hallImagesUrls = RxList<String>();
|
||||||
|
RImagePickerController hallImagesController = RImagePickerController();
|
||||||
RxList<XFile> hallImages = RxList<XFile>();
|
RxList<XFile> hallImages = RxList<XFile>();
|
||||||
|
|
||||||
RxList<String> inputWarehouseImagesUrls = RxList<String>();
|
RxList<String> inputWarehouseImagesUrls = RxList<String>();
|
||||||
|
RImagePickerController inputWarehouseImagesController =
|
||||||
|
RImagePickerController();
|
||||||
RxList<XFile> inputWarehouseImages = RxList<XFile>();
|
RxList<XFile> inputWarehouseImages = RxList<XFile>();
|
||||||
|
|
||||||
RxList<String> lossesImagesUrls = RxList<String>();
|
RxList<String> lossesImagesUrls = RxList<String>();
|
||||||
|
RImagePickerController lossesImagesController = RImagePickerController();
|
||||||
RxList<XFile> lossesImages = RxList<XFile>();
|
RxList<XFile> lossesImages = RxList<XFile>();
|
||||||
|
|
||||||
//location
|
//location
|
||||||
Rxn<LatLng> currentLocation = Rxn<LatLng>();
|
Rxn<LatLng> currentLocation = Rxn<LatLng>();
|
||||||
RxBool isLoadingLocation = false.obs;
|
RxBool isLoadingLocation = false.obs;
|
||||||
|
|
||||||
//images
|
|
||||||
ImagePicker imagePicker = ImagePicker();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
@@ -220,7 +221,9 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
setUpPultryImagesListener();
|
setUpPultryImagesListener();
|
||||||
|
setUpHallImagesListener();
|
||||||
|
setUpInputWarehouseImagesListener();
|
||||||
|
setUpLossesImagesListener();
|
||||||
initData();
|
initData();
|
||||||
setUpNextButtonListeners();
|
setUpNextButtonListeners();
|
||||||
}
|
}
|
||||||
@@ -570,32 +573,6 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pickImageFromCamera(RxList<XFile> images) async {
|
|
||||||
try {
|
|
||||||
final XFile? image = await imagePicker.pickImage(
|
|
||||||
source: ImageSource.camera,
|
|
||||||
preferredCameraDevice: CameraDevice.rear,
|
|
||||||
imageQuality: 50,
|
|
||||||
maxWidth: 1080,
|
|
||||||
maxHeight: 720,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (image != null) {
|
|
||||||
images.add(image);
|
|
||||||
|
|
||||||
//await uploadImage(image);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
Get.snackbar(
|
|
||||||
'خطا',
|
|
||||||
'خطا در باز کردن دوربین',
|
|
||||||
snackPosition: SnackPosition.TOP,
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
colorText: Colors.white,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<String>?> uploadImageBatch(List<XFile> images) async {
|
Future<List<String>?> uploadImageBatch(List<XFile> images) async {
|
||||||
if (images.isEmpty) return [];
|
if (images.isEmpty) return [];
|
||||||
|
|
||||||
@@ -964,7 +941,38 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
pultryImages.assignAll(pultryImagesController.capturedImages);
|
pultryImages.assignAll(pultryImagesController.capturedImages);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUpHallImagesListener() {
|
||||||
|
hallImagesController.addListener(() {
|
||||||
|
if (hallImagesController.capturedImages.isNotEmpty) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
hallImages.assignAll(hallImagesController.capturedImages);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUpInputWarehouseImagesListener() {
|
||||||
|
inputWarehouseImagesController.addListener(() {
|
||||||
|
if (inputWarehouseImagesController.capturedImages.isNotEmpty) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
inputWarehouseImages.assignAll(
|
||||||
|
inputWarehouseImagesController.capturedImages,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUpLossesImagesListener() {
|
||||||
|
lossesImagesController.addListener(() {
|
||||||
|
if (lossesImagesController.capturedImages.isNotEmpty) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
lossesImages.assignAll(lossesImagesController.capturedImages);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ Widget generalConditionOfTheHall(CreateInspectionBottomSheetLogic controller) {
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: 80.h,
|
height: 80.h,
|
||||||
width: 80.w,
|
width: 80.w,
|
||||||
|
margin: EdgeInsets.only(left: 8.h),
|
||||||
padding: EdgeInsets.all(22),
|
padding: EdgeInsets.all(22),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color(0xFFE9E9E9),
|
color: Color(0xFFE9E9E9),
|
||||||
|
|||||||
@@ -114,8 +114,15 @@ Column documents(CreateInspectionBottomSheetLogic controller) {
|
|||||||
),
|
),
|
||||||
// Add image button
|
// Add image button
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () =>
|
onTap: () => Get.to(
|
||||||
controller.pickImageFromCamera(controller.hallImages),
|
() => RImagePicker(
|
||||||
|
controller: controller.hallImagesController,
|
||||||
|
),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
transition: Transition.fade,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
),
|
||||||
|
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 80.h,
|
height: 80.h,
|
||||||
width: 80.w,
|
width: 80.w,
|
||||||
@@ -222,8 +229,13 @@ Column documents(CreateInspectionBottomSheetLogic controller) {
|
|||||||
),
|
),
|
||||||
// Add image button
|
// Add image button
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => controller.pickImageFromCamera(
|
onTap: () => Get.to(
|
||||||
controller.inputWarehouseImages,
|
() => RImagePicker(
|
||||||
|
controller: controller.inputWarehouseImagesController,
|
||||||
|
),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
transition: Transition.fade,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
),
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 80.h,
|
height: 80.h,
|
||||||
@@ -319,8 +331,13 @@ Column documents(CreateInspectionBottomSheetLogic controller) {
|
|||||||
),
|
),
|
||||||
// Add image button
|
// Add image button
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => controller.pickImageFromCamera(
|
onTap: () => Get.to(
|
||||||
controller.lossesImages,
|
() => RImagePicker(
|
||||||
|
controller: controller.lossesImagesController,
|
||||||
|
),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
transition: Transition.fade,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
),
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 80.h,
|
height: 80.h,
|
||||||
|
|||||||
Reference in New Issue
Block a user