fix(mobile): stop playing video when dismissing on iOS (#31772)

* fix(mobile): stop playing video when dismissing on iOS
This commit is contained in:
Adam Gastineau
2026-09-29 12:51:18 +00:00
committed by GitHub
parent 4d8219ef12
commit 3c3db5d0af
@@ -316,12 +316,17 @@ class NativeVideoViewerState extends ConsumerState<NativeVideoViewer> with Widge
Widget build(BuildContext context) {
final isCasting = ref.watch(castProvider.select((c) => c.isCasting));
final status = ref.watch(videoPlayerProvider(widget.asset.id).select((v) => v.status));
// https://github.com/flutter/flutter/issues/97499: iOS platform views are only disposed in frames containing platform views, or on
// the first frame after a platform view disappears. Animating this view away uses those disappearing frames. Instead, forcibly remove
// the view from the tree when we start a route transition, which has the side effect of properly ordering the `dispose`
final isRouteActive = ModalRoute.of(context)?.isActive ?? true;
final showPlayer = !isCasting && isRouteActive;
return IgnorePointer(
child: Stack(
children: [
if (!_isVideoReady || widget.asset.isMotionPhoto || isCasting) Positioned.fill(child: widget.image),
if (!isCasting) ...[
if (!_isVideoReady || widget.asset.isMotionPhoto || !showPlayer) Positioned.fill(child: widget.image),
if (showPlayer) ...[
Visibility.maintain(
visible: _isVideoReady,
child: NativeVideoPlayerView(onViewReady: _initController),