From 71e058af2e22cf210c97a13907396e4beebc37d9 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 16 Nov 2024 20:57:42 -0500 Subject: [PATCH] error handling for async calls --- .../pages/common/native_video_viewer.page.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mobile/lib/pages/common/native_video_viewer.page.dart b/mobile/lib/pages/common/native_video_viewer.page.dart index c7f4810260..fbb2bcd58f 100644 --- a/mobile/lib/pages/common/native_video_viewer.page.dart +++ b/mobile/lib/pages/common/native_video_viewer.page.dart @@ -65,7 +65,7 @@ class NativeVideoViewerPage extends HookConsumerWidget { final log = Logger('NativeVideoViewerPage'); final localEntity = useMemoized(() { - if (!asset.isLocal) { + if (!asset.isLocal || asset.isMotionPhoto) { return null; } @@ -116,7 +116,7 @@ class NativeVideoViewerPage extends HookConsumerWidget { return null; } - if (localEntity != null && asset.livePhotoVideoId == null) { + if (localEntity != null) { final file = await (await localEntity)!.file; if (file == null) { throw Exception('No file found for the video'); @@ -151,8 +151,18 @@ class NativeVideoViewerPage extends HookConsumerWidget { return null; } - final (videoSourceRes, aspectRatioRes) = - await (createSource(), calculateAspectRatio()).wait; + late final VideoSource? videoSourceRes; + late final double? aspectRatioRes; + try { + (videoSourceRes, aspectRatioRes) = + await (createSource(), calculateAspectRatio()).wait; + } catch (error) { + log.severe( + 'Error initializing video for asset ${asset.fileName}: $error', + ); + return; + } + if (videoSourceRes == null || aspectRatioRes == null) { return; }