diff --git a/android/app/src/main/kotlin/com/example/mini_tias/RawCapturePlugin.kt b/android/app/src/main/kotlin/com/example/mini_tias/RawCapturePlugin.kt index e6f8962..9581a0e 100644 --- a/android/app/src/main/kotlin/com/example/mini_tias/RawCapturePlugin.kt +++ b/android/app/src/main/kotlin/com/example/mini_tias/RawCapturePlugin.kt @@ -72,6 +72,8 @@ maxSize.width, maxSize.height, ImageFormat.YUV_420_888, 2 ) + var resultSent = false + try { cameraManager.openCamera(cameraId, object : CameraDevice.StateCallback() { override fun onOpened(camera: CameraDevice) { @@ -108,7 +110,9 @@ // ここでリスナーを設定(本番フレームのみ受信) imageReader.setOnImageAvailableListener({ reader -> + if (resultSent) return@setOnImageAvailableListener val image = reader.acquireLatestImage() ?: return@setOnImageAvailableListener + resultSent = true try { val yPlane = image.planes[0] diff --git a/lib/providers/camera_provider.dart b/lib/providers/camera_provider.dart index db5e749..4c5fddb 100644 --- a/lib/providers/camera_provider.dart +++ b/lib/providers/camera_provider.dart @@ -73,6 +73,7 @@ if (!_isInitialized || _isSaving) return; _isSaving = true; + _isInitialized = false; notifyListeners(); try { @@ -88,7 +89,6 @@ // プレビューを停止してカメラを解放 await _controller?.dispose(); _controller = null; - _isInitialized = false; // カメラが完全に解放されるまで待つ await Future.delayed(const Duration(milliseconds: 500)); diff --git a/lib/providers/gallery_provider.dart b/lib/providers/gallery_provider.dart index 3cc00ed..35fb41b 100644 --- a/lib/providers/gallery_provider.dart +++ b/lib/providers/gallery_provider.dart @@ -55,9 +55,13 @@ if (await file.exists()) { await file.delete(); } - _images.remove(file); - notifyListeners(); - return true; + // 削除成功後にのみ一覧から除去 + if (!await file.exists()) { + _images.remove(file); + notifyListeners(); + return true; + } + return false; } catch (e) { debugPrint('画像の削除に失敗: $e'); return false; diff --git a/lib/services/raw_capture_service.dart b/lib/services/raw_capture_service.dart index 7e520a9..8a92d39 100644 --- a/lib/services/raw_capture_service.dart +++ b/lib/services/raw_capture_service.dart @@ -11,7 +11,12 @@ /// - yPlane, uPlane, vPlane: YUV プレーンのバイトデータ /// - yRowStride, uvRowStride, uvPixelStride: ストライド情報 Future> captureFullResolutionYuv() async { - final result = await _channel.invokeMethod('captureFullResolutionYuv'); + final result = await _channel + .invokeMethod('captureFullResolutionYuv') + .timeout( + const Duration(seconds: 30), + onTimeout: () => throw Exception('カメラキャプチャがタイムアウトしました'), + ); return Map.from(result as Map); }