Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
949 stars 240 forks source link

Camera doesn't close on dispose #156

Closed itsMatoosh closed 1 year ago

itsMatoosh commented 1 year ago

When the CameraAwesomeBuilder widget is disposed, the underlying camera session is not being closed. This causes performance issues in the app after using the camera. I am using version 1.0.0 from the master branch.

g-apparence commented 1 year ago

Thank you reporting it. We are going to take a look at it. 👌

apalala-dev commented 1 year ago

Can you provide more details on how you use CameraAwesomeBuilder ? I have difficulties reproducing the problem. An example would help 👌

itsMatoosh commented 1 year ago

This is the builder I'm using. I have a custom layout widget CameraOverlay with simple buttons for flash mode and camera sensor switching.

CameraAwesomeBuilder.custom(
  initialCaptureMode: CaptureModes.PHOTO,
  availableModes: const [
    CaptureModes.PHOTO,
  ],
  picturePathBuilder: (captureMode) => _path(captureMode),
  videoPathBuilder: (captureMode) => _path(captureMode),
  builder: (cameraModeState) => CameraOverlay(
    cameraState: cameraModeState,
  ),
  progressIndicator: const Center(
    child: Icon(
      Ionicons.camera,
      size: 50,
    ),
  ),
  exifPreferences: ExifPreferences(saveGPSLocation: false),
),

When the CameraAwesomeBuilder widget is disposed (ex. when the camera page is closed), the camera session stays on as indicated by the green dot in the status bar on Android.

It looks like an issue with the internal start/stop state management within the package. The state isn't correctly set as started when a camera session begins and therefore the close method doesn't run. I created a quick fix for this issue in my fork: https://github.com/itsMatoosh/camera_awesome. Please take a look.

itsMatoosh commented 1 year ago

This was fixed in the latest commits, thanks!