From 45a6ea84af6a43ed284e8f7da320d008e1068089 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Mon, 20 Jul 2026 12:00:37 -0700 Subject: [PATCH] fix(mobile): prevent crash on video widget dispose (#30078) --- .../widgets/asset_viewer/video_viewer.widget.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart b/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart index 87f97d5754..ccbaf7660a 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/video_viewer.widget.dart @@ -91,7 +91,7 @@ class _NativeVideoViewerState extends ConsumerState with Widg } case AppLifecycleState.paused: _shouldPlayOnForeground = await _controller?.isPlaying() ?? true; - if (_shouldPlayOnForeground) { + if (_shouldPlayOnForeground && mounted) { await _notifier.pause(); } default: @@ -268,10 +268,13 @@ class _NativeVideoViewerState extends ConsumerState with Widg return; } - await _notifier.load(source); + // Grab refs to prevent reading after dispose final loopVideo = ref.read(appConfigProvider).viewer.loopVideo; - await _notifier.setLoop(!widget.asset.isMotionPhoto && loopVideo); - await _notifier.setVolume(1); + final localNotifier = _notifier; + + await localNotifier.load(source); + await localNotifier.setLoop(!widget.asset.isMotionPhoto && loopVideo); + await localNotifier.setVolume(1); } void _initController(NativeVideoPlayerController nc) {