diff --git a/mobile/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/lib/ui/viewer/gallery/component/gallery_file_widget.dart index d8cb2d4743..15d5f91f5b 100644 --- a/mobile/lib/ui/viewer/gallery/component/gallery_file_widget.dart +++ b/mobile/lib/ui/viewer/gallery/component/gallery_file_widget.dart @@ -53,15 +53,18 @@ class _GalleryFileWidgetState extends State { final _logger = Logger("GalleryFileWidget"); @override - void initState() { - super.initState(); + void didChangeDependencies() { + super.didChangeDependencies(); if (!widget.limitSelectionToOne) { WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) { try { final RenderBox? renderBox = _globalKey.currentContext?.findRenderObject() as RenderBox?; - if (renderBox == null) return; + if (renderBox == null) { + _logger.info("RenderBox is null. Returning."); + return; + } final groupGalleryGlobalKey = GroupGalleryGlobalKey.of(context).globalKey; @@ -69,7 +72,10 @@ class _GalleryFileWidgetState extends State { final RenderBox? groupGalleryRenderBox = groupGalleryGlobalKey.currentContext?.findRenderObject() as RenderBox?; - if (groupGalleryRenderBox == null) return; + if (groupGalleryRenderBox == null) { + _logger.info("GroupGalleryRenderBox is null. Returning."); + return; + } final position = renderBox.localToGlobal( Offset.zero, @@ -94,26 +100,32 @@ class _GalleryFileWidgetState extends State { } }); - _pointerPositionStreamSubscription = Pointer.of(context) - .moveOffsetStreamController - .stream - .listen((event) { - if (widget.selectedFiles?.files.isEmpty ?? true) return; - _insideBboxPrevValue = _pointerInsideBbox; + _pointerPositionStreamSubscription = + Pointer.of(context).moveOffsetStreamController.stream.listen( + (event) { + if (widget.selectedFiles?.files.isEmpty ?? true) return; + _insideBboxPrevValue = _pointerInsideBbox; - if (bbox.contains(event)) { - _pointerInsideBbox = true; - } else { - _pointerInsideBbox = false; - } + if (bbox.contains(event)) { + _pointerInsideBbox = true; + } else { + _pointerInsideBbox = false; + } - if (_pointerInsideBbox == true && _insideBboxPrevValue == false) { - // print('Entered ${widget.file.displayName}'); - widget.selectedFiles!.toggleSelection(widget.file); - } - }); + if (_pointerInsideBbox == true && + _insideBboxPrevValue == false) { + widget.selectedFiles!.toggleSelection(widget.file); + } + }, + onError: (e) { + _logger.warning("Error in pointer position subscription", e); + }, + onDone: () { + _logger.info("Pointer position subscription done"); + }, + ); } catch (e) { - _logger.warning("Error in pointer position subscription", e); + _logger.warning("Error in pointer subscription", e); } } }); diff --git a/mobile/lib/ui/viewer/gallery/component/grid/lazy_grid_view.dart b/mobile/lib/ui/viewer/gallery/component/grid/lazy_grid_view.dart index 248b4c5664..06ecb178a7 100644 --- a/mobile/lib/ui/viewer/gallery/component/grid/lazy_grid_view.dart +++ b/mobile/lib/ui/viewer/gallery/component/grid/lazy_grid_view.dart @@ -44,6 +44,7 @@ class _LazyGridViewState extends State { @override void initState() { + super.initState(); _shouldRender = widget.shouldRender; _currentUserID = Configuration.instance.getUserID(); widget.selectedFiles?.addListener(_selectedFilesListener); @@ -53,7 +54,6 @@ class _LazyGridViewState extends State { setState(() {}); } }); - super.initState(); } @override