How to pause camera preview?

Viewed 532

I am using Flutter's camera plugin to get a live camera preview. But I want to freeze CameraPreview when the user taps the button. So that the picture will stay on the screen when the user taps on the button.

For example in Android: camera.stopPreview();

I cannot use stopImageStream() because I am not streaming the image.

Does anyone know how to do this?

1 Answers

A way this is accomplished is by establishing a counter and incrementing it, and pausing the camera controller when the pauseCamera value is odd.

var pauseCamera = 0;
CameraController? camera; //From the camera package.
...
FloatingActionButton(
          onPressed: () {
            pauseCamera++;
            pauseCamera.isOdd
                ? camera!.pausePreview()
                : camera!.resumePreview();
          },
          child: CameraView(),
        ),
Related