From 26f58d33350c84ef056cec53aa858b42cf62fa08 Mon Sep 17 00:00:00 2001 From: martyfuhry Date: Tue, 20 Jun 2023 20:58:17 -0400 Subject: [PATCH] Fixes local position late initialization (#2884) --- .../lib/modules/asset_viewer/views/gallery_viewer.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart b/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart index 7661bd5085..38a79abd7e 100644 --- a/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart +++ b/mobile/lib/modules/asset_viewer/views/gallery_viewer.dart @@ -52,7 +52,7 @@ class GalleryViewerPage extends HookConsumerWidget { final showAppBar = useState(true); final isPlayingMotionVideo = useState(false); final isPlayingVideo = useState(false); - late Offset localPosition; + Offset? localPosition; final authToken = 'Bearer ${Store.get(StoreKey.accessToken)}'; final currentIndex = useState(initialIndex); final currentAsset = loadAsset(currentIndex.value); @@ -246,8 +246,13 @@ class GalleryViewerPage extends HookConsumerWidget { return; } + // Guard [localPosition] null + if (localPosition == null) { + return; + } + // Check for delta from initial down point - final d = details.localPosition - localPosition; + final d = details.localPosition - localPosition!; // If the magnitude of the dx swipe is large, we probably didn't mean to go down if (d.dx.abs() > dxThreshold) { return;