diff --git a/sigap-mobile/lib/src/features/auth/presentasion/controllers/signup/step/selfie-verification/selfie_verification_controller.dart b/sigap-mobile/lib/src/features/auth/presentasion/controllers/signup/step/selfie-verification/selfie_verification_controller.dart index 60c1e2f..db419c8 100644 --- a/sigap-mobile/lib/src/features/auth/presentasion/controllers/signup/step/selfie-verification/selfie_verification_controller.dart +++ b/sigap-mobile/lib/src/features/auth/presentasion/controllers/signup/step/selfie-verification/selfie_verification_controller.dart @@ -116,45 +116,18 @@ class SelfieVerificationController extends GetxController { await Get.delete(); } - // Register a new controller (will be done automatically by the widget) - final result = await Get.toNamed( + // Navigate to liveness detection page and wait for result + await Get.toNamed( AppRoutes.livenessDetection, preventDuplicates: false, // Allow navigation to same route if needed ); - // Handle the result based on what was returned - if (result is XFile) { - // Liveness check passed and returned an image - dev.log( - 'Received result from liveness detection, setting selfie image', - name: 'SELFIE_VERIFICATION', - ); - - selfieImage.value = result; - isLivenessCheckPassed.value = true; - isPerformingLivenessCheck.value = false; + // When returning here, the image should already be set by CapturedSelfieView + // and automatic verification should be triggered by the listener in onInit + + // Reset liveness check flag since we're back + isPerformingLivenessCheck.value = false; - // The _processCapturedLivenessImage will be called automatically - // due to the ever() listener we set up in onInit - } else if (result == 'navigation_handled') { - // Special case: navigation was handled by the captured selfie view - // The user was already navigated back to this screen - dev.log( - 'Navigation handled by captured selfie view', - name: 'SELFIE_VERIFICATION', - ); - isPerformingLivenessCheck.value = false; - // Don't reset other states since they should be set by the captured view - } else { - // User cancelled or something went wrong - dev.log( - 'No result from liveness detection, reset states', - name: 'SELFIE_VERIFICATION', - ); - isPerformingLivenessCheck.value = false; - isLivenessCheckPassed.value = false; - autoStartVerification = false; - } } catch (e) { dev.log('Error in liveness detection: $e', name: 'SELFIE_VERIFICATION'); isPerformingLivenessCheck.value = false; diff --git a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/liveness_detection_screen.dart b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/liveness_detection_screen.dart index 0e05868..55519da 100644 --- a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/liveness_detection_screen.dart +++ b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/liveness_detection_screen.dart @@ -125,10 +125,11 @@ class LivenessDetectionPage extends StatelessWidget { icon: const Icon(Icons.arrow_back, color: Colors.black87), onPressed: () { dev.log('Back button pressed', name: 'LIVENESS_DEBUG'); - if (selfieController != null) { - dev.log('Handling cancellation', name: 'LIVENESS_DEBUG'); - controller.handleCancellation(); - } + + // Ensure we clean up resources when going back + controller.handleCancellation(); + + // This allows the user to go back to selfie verification step Get.back(); }, ), diff --git a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/selfie_verification_step.dart b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/selfie_verification_step.dart index 520d611..17f7231 100644 --- a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/selfie_verification_step.dart +++ b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/selfie_verification_step.dart @@ -397,7 +397,13 @@ class SelfieVerificationStep extends StatelessWidget { ), const SizedBox(height: TSizes.spaceBtwItems), ElevatedButton.icon( - onPressed: controller.performLivenessDetection, + onPressed: () { + // Clear any previous images or states before starting new verification + controller.clearSelfieImage(); + controller.resetVerificationState(); + // Start liveness detection process + controller.performLivenessDetection(); + }, icon: const Icon(Icons.security), label: const Text('Start Face Verification'), style: ElevatedButton.styleFrom( diff --git a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/widgets/captured_selfie_view.dart b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/widgets/captured_selfie_view.dart index 5bc5fb4..d842d13 100644 --- a/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/widgets/captured_selfie_view.dart +++ b/sigap-mobile/lib/src/features/auth/presentasion/pages/signup/step/selfie-verification/widgets/captured_selfie_view.dart @@ -666,7 +666,7 @@ class _CapturedSelfieViewState extends State // Set flag to automatically start verification upon returning widget.selfieController!.autoStartVerification = true; - // Set the captured image in the selfie controller - do this last + // Set the captured image in the selfie controller widget.selfieController!.selfieImage.value = xFile; dev.log( @@ -677,30 +677,13 @@ class _CapturedSelfieViewState extends State // Now dispose the camera after we've handled the image widget.controller.disposeCamera(); - // Update the controller to ensure changes propagate - widget.selfieController!.update(); - - // Wait a moment to ensure the image is properly set - await Future.delayed(Duration(milliseconds: 100)); - - // Navigate back to selfie verification step by removing liveness detection from stack - if (mounted && !isDisposed) { - // Use Get.offAll to clear the entire navigation stack and go to signup page - // The signup page will show the selfie verification step since we've set the image - Get.offAllNamed('/signup'); // Replace with your actual signup route - - // Alternative: if you know the exact route name for selfie verification step - // Get.offNamed('/signup/selfie-verification'); - } + // Simply go back to the previous screen (selfie verification step) + Get.back(); } else { widget.controller.disposeCamera(); if (mounted && !isDisposed) { - Get.back( - closeOverlays: true, - canPop: true, - result: widget.controller.capturedImage, - ); + Get.back(result: widget.controller.capturedImage); } } } catch (e) { @@ -711,8 +694,7 @@ class _CapturedSelfieViewState extends State if (mounted && !isDisposed) { isComparingWithID.value = false; - errorMessage.value = - 'Failed to process the captured image: $e'; + errorMessage.value = 'Failed to process the captured image: $e'; } } }