Dispose method
Implementation
Future<void> Dispose() async {
// Dispose MLKit face detector
// Stop face detection
await _faceDetector.close();
// Dispose camera in the background
final controller = cameraController;
cameraController = null;
if (controller != null) {
if (controller.value.isStreamingImages) {
await controller.stopImageStream();
}
Future.microtask(() => controller.dispose()); // Non-blocking dispose
}
hasCapturedImage = false;
_isInitialized = false;
isCameraReady.value = false;
capturedImageNotifier.value = null;
isCameraSwitching.value = false;
_resetDetectionState();
}