feat: enhance CreateInspectionBottomSheetLogic with image listener setup and improve camera controller functionality for better user experience

This commit is contained in:
2025-12-16 14:38:06 +03:30
parent 39ca4f0c35
commit 4f7fa4ba93
4 changed files with 68 additions and 12 deletions

View File

@@ -209,6 +209,10 @@ class CreateInspectionBottomSheetLogic extends GetxController
void onReady() {
super.onReady();
activeStepperIndex.listen((value) {
iLog("==========>$value");
if (value == 1) {
setUpPultryImagesListener();
}
pageController.animateToPage(
value,
duration: Duration(milliseconds: 300),
@@ -956,7 +960,12 @@ class CreateInspectionBottomSheetLogic extends GetxController
void setUpPultryImagesListener() {
pultryImagesController.addListener(() {
if (pultryImagesController.capturedImages.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
pultryImages.assignAll(pultryImagesController.capturedImages);
});
}
});
}
}

View File

@@ -74,7 +74,7 @@ Widget generalConditionOfTheHall(CreateInspectionBottomSheetLogic controller) {
children: [
ObxValue((data) {
return Row(
children: data.value
children: data
.map(
(entry) => Stack(
children: [

View File

@@ -8,41 +8,57 @@ class RImagePickerController extends ChangeNotifier {
CameraController? cameraController;
bool isLoading = false;
bool isCameraReady = false;
bool frontCamera = true;
bool isCameraLoading = false;
bool hasTwoCameras = false;
List<XFile> capturedImages = <XFile>[];
Future<void> getAvailableCameras() async {
_cameras = await availableCameras();
if (_cameras.length > 1) {
hasTwoCameras = true;
}
}
Future<void> openCamera() async {
try {
isLoading = true;
isCameraLoading = true;
await disposeCameraController();
await getAvailableCameras();
if (_cameras.isNotEmpty) {
if (hasTwoCameras && frontCamera) {
cameraController = CameraController(
_cameras[0],
ResolutionPreset.high,
enableAudio: false,
);
}
if (hasTwoCameras && !frontCamera) {
cameraController = CameraController(
_cameras[1],
ResolutionPreset.high,
enableAudio: false,
);
}
await cameraController?.initialize();
isCameraReady = true;
isLoading = false;
isCameraLoading = false;
notifyListeners();
} else {
isCameraReady = false;
isLoading = false;
isCameraLoading = false;
notifyListeners();
}
} catch (e) {
isCameraReady = false;
isLoading = false;
isCameraLoading = false;
notifyListeners();
eLog(e);
}
@@ -59,7 +75,7 @@ class RImagePickerController extends ChangeNotifier {
notifyListeners();
final image = await cameraController!.takePicture();
capturedImages.add(image);
capturedImages.insert(0, image);
isLoading = false;
} catch (e) {

View File

@@ -92,6 +92,37 @@ class _RImagePickerState extends State<RImagePicker> {
),
],
Positioned(
bottom: 40,
left: 10,
child: Center(
child: FloatingActionButton(
onPressed: widget.controller.isCameraLoading
? null
: () async {
widget.controller.frontCamera =
!widget.controller.frontCamera;
await widget.controller.openCamera();
},
backgroundColor: Colors.white,
child: widget.controller.isCameraLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.black,
),
),
)
: const Icon(Icons.cameraswitch, color: Colors.black),
),
),
),
if (widget.controller.capturedImages.isNotEmpty) ...[
Positioned(
bottom: 120,