Fix black screen issue when taking photos on Huawei phones#325
Open
lancexin wants to merge 1 commit into
Open
Conversation
…n on Huawei phones The main reason is that the exposure was not reset back after obtaining the image
AlexV525
reviewed
May 25, 2026
| ); | ||
| } | ||
|
|
||
| await controller.pausePreview(); |
Member
There was a problem hiding this comment.
Would it be better to call these methods after the preview is paused?
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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