Repository navigation
Fix black viewfinder after resuming from background - #135
Merged
iakdis merged 1 commit intoSep 25, 2026
Merged
Conversation
Camera lifecycle handling tore the camera down on AppLifecycleState.inactive, which fires for transient interruptions like the notification shade or a system dialog, not just real backgrounding. Because dispose()/initialize() calls were unawaited and unserialized, inactive/resumed events firing in quick succession could overlap them, leaving the native preview surface detached from the repeating capture request while the controller still reported itself initialized (so photo capture kept working, but the preview stayed black until the app was fully killed and relaunched). - Only tear the camera down on paused/hidden; inactive is now a no-op. - Serialize hide/show through a single queued future so dispose() and initialize() can never overlap. - Rebuild the preview from the live controller inside the ValueListenableBuilder instead of a stale reference captured outside it, and key CameraPreview on the controller's camera id so a new controller gets a fresh texture subtree. - Recover safely if the controller is missing/uninitialized when switching cameras or toggling video mode instead of calling into a dead controller.
This was referenced Sep 6, 2026
Contributor
Author
|
Morning - any chance of getting this reviewer and merged? 😇 |
Owner
|
Hi @AlexanderWalls, thank you for the PR! I just tested it myself and it looks good on my side. I'll also merge your other PR. Thanks again for the contributions! |
Contributor
Author
You're totally welcome! I'm also experiencing a no sound issue when recording video, so will investigate that separately |
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.
Summary
Fixes the camera preview going permanently black after any resume from the background — including brief interruptions like pulling down the notification shade, not just switching apps.
Root cause: camera teardown was triggered on
AppLifecycleState.inactive, which fires for transient interruptions (shade pull, system dialogs) as well as real backgrounding. The resultingdispose()/initialize()calls were unawaited and unserialized, so overlapping lifecycle events could race the native camera controller — the plugin would report itself initialized (so photo capture kept working) while the preview surface never got reattached, leaving it black until the app was fully killed and relaunched.Changes
paused/hidden;inactiveis now a no-op.dispose()andinitialize()can never overlap.ValueListenableBuilderinstead of a stale reference captured outside it, and keyCameraPreviewon the controller's camera id so a new controller gets a fresh texture subtree.Fixes #127.
Test plan
flutter analyzeclean