Skip to content

[video_player] Build an empty view when the player is already disposed - #12405

Open
wilyan09007 wants to merge 1 commit into
flutter:mainfrom
wilyan09007:fix/issue-190739
Open

[video_player] Build an empty view when the player is already disposed#12405
wilyan09007 wants to merge 1 commit into
flutter:mainfrom
wilyan09007:fix/issue-190739

Conversation

@wilyan09007

@wilyan09007 wilyan09007 commented Aug 8, 2026

Copy link
Copy Markdown

buildViewWithOptions resolves the player through _playerWith, which throws a StateError when the id is no longer present in _players. Disposal and the next frame are not synchronized, so a widget still holding a disposed player can be rebuilt during an AnimatedSwitcher transition, or by a rebuild that a configuration change triggers once the platform has reclaimed the player. Because this runs inside build, the throw leaves the video view permanently broken rather than simply rendering nothing.

Both platform implementations now look the player up directly and build an empty view when it is gone.

Fixes flutter/flutter#190739

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

buildViewWithOptions resolved the player through _playerWith, which throws a
StateError when the id is no longer in _players. Disposal and the next frame
are not synchronized, so a widget holding a disposed player can still be
rebuilt -- an AnimatedSwitcher transition, or a rebuild triggered by a
configuration change once the platform has reclaimed the player. Throwing from
a build method leaves the video widget permanently broken rather than simply
rendering nothing.

Look the player up directly and build an empty view when it is gone, on both
the Android and AVFoundation implementations.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates both the Android and AVFoundation implementations of the video_player plugin to return an empty view (SizedBox.shrink()) instead of throwing a StateError when building a view for a disposed player. It also includes corresponding unit tests and version bumps for both packages. There are no review comments, and I have no feedback to provide.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] _playerWith throws unrecoverable StateError when native player is destroyed by OS during CONFIGURATION_CHANGED / LOW_MEMORY

1 participant