Skip to content

Fix black screen issue when taking photos on Huawei phones#325

Open
lancexin wants to merge 1 commit into
fluttercandies:mainfrom
lancexin:main
Open

Fix black screen issue when taking photos on Huawei phones#325
lancexin wants to merge 1 commit into
fluttercandies:mainfrom
lancexin:main

Conversation

@lancexin

Copy link
Copy Markdown

After taking a photo on some Huawei phones and entering again, the preview screen will turn black.

The reason is that the exposure was not reset before returning the image

…n on Huawei phones

The main reason is that the exposure was not reset back after obtaining the image
@lancexin lancexin requested a review from AlexV525 as a code owner May 25, 2026 03:05
);
}

await controller.pausePreview();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to call these methods after the preview is paused?

@lancexin lancexin May 25, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried it before, but I found that there are some issues with doing so. Here is the code I have modified:

   await controller.pausePreview();
    //The photo has been taken and we need to reset the focus and exposure here
    await wrapControllerMethod<void>('setFocusMode', () async {
      realDebugPrint("wrapControllerMethod  setFocusMode start");
      await innerController?.setFocusMode(FocusMode.auto);
      realDebugPrint("wrapControllerMethod  setFocusMode end");
    }).catchError((e, s) {
      realDebugPrint("wrapControllerMethod setFocusMode error $e");
      return Future.value();
    });
    if (previousExposureMode != ExposureMode.locked) {
      await wrapControllerMethod<void>('setExposureMode', () async {
        realDebugPrint("wrapControllerMethod  setExposureMode start");
        await innerController?.setExposureMode(previousExposureMode);
        //never called here
        realDebugPrint("wrapControllerMethod  setExposureMode end");
      }).catchError((e, s) {
        realDebugPrint("wrapControllerMethod setExposureMode error $e");
        return Future.value();
      });
    }
[CameraPicker - LOG] 0:00:00.156427 for controller's initialization.
[CameraPicker - LOG] 0:00:00.092799 for config's update.
[CameraPicker - LOG] wrapControllerMethod  setFocusMode start
[CameraPicker - LOG] wrapControllerMethod  setFocusMode end
[CameraPicker - LOG] wrapControllerMethod  setExposureMode start
//block here and never print 'wrapControllerMethod  setExposureMode end'

I found that calling pausePreview and then calling the setExposureMode method would block, and I haven't figured out why this is happening yet. I found that someone in the Issues also mentioned that calling setExposureMode/setFocusMode during initialization can also be blocked. I guess there is some bug among Huawei phones.

But I found that by changing the code to the following (changing the position of pausePreview), the blocking disappeared:

      //The photo has been taken and we need to reset the focus and exposure here
      await wrapControllerMethod<void>('setFocusMode', () async {
        realDebugPrint("wrapControllerMethod  setFocusMode start");
        await innerController?.setFocusMode(FocusMode.auto);
        realDebugPrint("wrapControllerMethod  setFocusMode end");
      }).catchError((e, s) {
        realDebugPrint("wrapControllerMethod setFocusMode error $e");
        return Future.value();
      });
      if (previousExposureMode != ExposureMode.locked) {
        await wrapControllerMethod<void>('setExposureMode', () async {
          realDebugPrint("wrapControllerMethod  setExposureMode start");
          await innerController?.setExposureMode(previousExposureMode);
          //never called here
          realDebugPrint("wrapControllerMethod  setExposureMode end");
        }).catchError((e, s) {
          realDebugPrint("wrapControllerMethod setExposureMode error $e");
          return Future.value();
        });
      }
      await controller.pausePreview();
[CameraPicker - LOG] 0:00:00.225070 for controller's initialization.
[CameraPicker - LOG] 0:00:00.038097 for config's update.
[CameraPicker - LOG] wrapControllerMethod  setFocusMode start
[CameraPicker - LOG] wrapControllerMethod  setFocusMode end
[CameraPicker - LOG] wrapControllerMethod  setExposureMode start
[CameraPicker - LOG] wrapControllerMethod  setExposureMode end
[CameraPicker - LOG] Preview image cache evicted: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants