π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Simplify stale detail page guard
Neeraj Gupta1f0b31d24684
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dartindex 502de3dccb..674de196b1 100644--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart@@ -159,9 +159,12 @@ class _BodyState extends State<_Body> {super.initState();_files = widget.config.files;- final selectedIndex = _initialSelectedIndex();- _selectedIndexNotifier.value = selectedIndex ?? -1;- _pageController = PageController(initialPage: selectedIndex ?? 0);+ final configuredIndex = widget.config.selectedIndex;+ final selectedIndex = _fileAt(configuredIndex) == null+ ? -1+ : configuredIndex;+ _selectedIndexNotifier.value = selectedIndex;+ _pageController = PageController(initialPage: max(0, selectedIndex));_guestViewEventSubscription = Bus.instance.on<GuestViewEvent>().listen((event,) {@@ -613,18 +616,6 @@ class _BodyState extends State<_Body> {}}- int? _initialSelectedIndex() {- final files = _files;- if (files == null || files.isEmpty) {- return null;- }- final selectedIndex = widget.config.selectedIndex;- if (selectedIndex < 0 || selectedIndex >= files.length) {- return null;- }- return selectedIndex;- }-EnteFile? get _selectedFile => _fileAt(_selectedIndexNotifier.value);EnteFile? _fileAt(int index) {diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dartindex 759369bc41..78950a2964 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart@@ -287,6 +287,7 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {void _routeToDetailPage(EnteFile file, BuildContext context) {final galleryFiles = GalleryFilesState.of(context).galleryFiles;final selectedIndex = galleryFiles.indexOf(file);+ // A refresh can make the tapped tile stale.if (selectedIndex < 0) {return;}