feat: enhance CreateInspectionBottomSheetLogic with image listener setup and improve camera controller functionality for better user experience
This commit is contained in:
@@ -209,6 +209,10 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
activeStepperIndex.listen((value) {
|
activeStepperIndex.listen((value) {
|
||||||
|
iLog("==========>$value");
|
||||||
|
if (value == 1) {
|
||||||
|
setUpPultryImagesListener();
|
||||||
|
}
|
||||||
pageController.animateToPage(
|
pageController.animateToPage(
|
||||||
value,
|
value,
|
||||||
duration: Duration(milliseconds: 300),
|
duration: Duration(milliseconds: 300),
|
||||||
@@ -956,7 +960,12 @@ class CreateInspectionBottomSheetLogic extends GetxController
|
|||||||
|
|
||||||
void setUpPultryImagesListener() {
|
void setUpPultryImagesListener() {
|
||||||
pultryImagesController.addListener(() {
|
pultryImagesController.addListener(() {
|
||||||
pultryImages.assignAll(pultryImagesController.capturedImages);
|
if (pultryImagesController.capturedImages.isNotEmpty) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
pultryImages.assignAll(pultryImagesController.capturedImages);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ Widget generalConditionOfTheHall(CreateInspectionBottomSheetLogic controller) {
|
|||||||
children: [
|
children: [
|
||||||
ObxValue((data) {
|
ObxValue((data) {
|
||||||
return Row(
|
return Row(
|
||||||
children: data.value
|
children: data
|
||||||
.map(
|
.map(
|
||||||
(entry) => Stack(
|
(entry) => Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -8,41 +8,57 @@ class RImagePickerController extends ChangeNotifier {
|
|||||||
CameraController? cameraController;
|
CameraController? cameraController;
|
||||||
|
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
|
||||||
bool isCameraReady = false;
|
bool isCameraReady = false;
|
||||||
|
bool frontCamera = true;
|
||||||
|
bool isCameraLoading = false;
|
||||||
|
bool hasTwoCameras = false;
|
||||||
|
|
||||||
List<XFile> capturedImages = <XFile>[];
|
List<XFile> capturedImages = <XFile>[];
|
||||||
|
|
||||||
Future<void> getAvailableCameras() async {
|
Future<void> getAvailableCameras() async {
|
||||||
_cameras = await availableCameras();
|
_cameras = await availableCameras();
|
||||||
|
if (_cameras.length > 1) {
|
||||||
|
hasTwoCameras = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> openCamera() async {
|
Future<void> openCamera() async {
|
||||||
try {
|
try {
|
||||||
isLoading = true;
|
isCameraLoading = true;
|
||||||
await disposeCameraController();
|
await disposeCameraController();
|
||||||
|
|
||||||
await getAvailableCameras();
|
await getAvailableCameras();
|
||||||
|
|
||||||
if (_cameras.isNotEmpty) {
|
if (_cameras.isNotEmpty) {
|
||||||
cameraController = CameraController(
|
if (hasTwoCameras && frontCamera) {
|
||||||
_cameras[0],
|
cameraController = CameraController(
|
||||||
ResolutionPreset.high,
|
_cameras[0],
|
||||||
enableAudio: false,
|
ResolutionPreset.high,
|
||||||
);
|
enableAudio: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (hasTwoCameras && !frontCamera) {
|
||||||
|
cameraController = CameraController(
|
||||||
|
_cameras[1],
|
||||||
|
ResolutionPreset.high,
|
||||||
|
enableAudio: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await cameraController?.initialize();
|
await cameraController?.initialize();
|
||||||
|
|
||||||
isCameraReady = true;
|
isCameraReady = true;
|
||||||
isLoading = false;
|
isCameraLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else {
|
} else {
|
||||||
isCameraReady = false;
|
isCameraReady = false;
|
||||||
isLoading = false;
|
isCameraLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isCameraReady = false;
|
isCameraReady = false;
|
||||||
isLoading = false;
|
isCameraLoading = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
eLog(e);
|
eLog(e);
|
||||||
}
|
}
|
||||||
@@ -59,7 +75,7 @@ class RImagePickerController extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
final image = await cameraController!.takePicture();
|
final image = await cameraController!.takePicture();
|
||||||
|
|
||||||
capturedImages.add(image);
|
capturedImages.insert(0, image);
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -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) ...[
|
if (widget.controller.capturedImages.isNotEmpty) ...[
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 120,
|
bottom: 120,
|
||||||
|
|||||||
Reference in New Issue
Block a user