From 8f08ab18fcd66d498ed7c1c289536cb05a18acaa Mon Sep 17 00:00:00 2001 From: Aman Raj Singh Mourya Date: Mon, 29 Jul 2024 15:56:48 +0530 Subject: [PATCH] [mob][photos] MInor changes --- mobile/lib/utils/share_util.dart | 69 +++++++++++++++----------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/mobile/lib/utils/share_util.dart b/mobile/lib/utils/share_util.dart index 4a97b3c98b..eb7b78d391 100644 --- a/mobile/lib/utils/share_util.dart +++ b/mobile/lib/utils/share_util.dart @@ -254,48 +254,13 @@ Future shareImageAndUrl( ); } -/// required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383 -/// This returns the position of the share button if context and key are not null -/// and if not, it returns a default position so that the share sheet on iPad has -/// some position to show up. -Rect _sharePosOrigin(BuildContext? context, GlobalKey? key) { - late final Rect rect; - if (context != null) { - rect = shareButtonRect(context, key); - } else { - rect = const Offset(20.0, 20.0) & const Size(10, 10); - } - return rect; -} - -/// The [ScreenshotController] is used to capture the image of a widget that serves as -/// a placeholder for an album link. The placeholder is then shared along with the album link. -final ScreenshotController screenshotController = ScreenshotController(); - -Future _createAlbumPlaceholder( - List files, - ScreenshotController screenshotController, - BuildContext context, -) async { - final Widget imageWidget = LinkPlaceholder( - files: files, - ); - final double pixelRatio = MediaQuery.devicePixelRatioOf(context); - final bytesOfImageToWidget = await screenshotController.captureFromWidget( - imageWidget, - pixelRatio: pixelRatio, - targetSize: MediaQuery.sizeOf(context), - delay: const Duration(milliseconds: 300), - ); - return bytesOfImageToWidget; -} - Future shareAlbumLinkWithPlaceholder( BuildContext context, Collection collection, String url, GlobalKey key, ) async { + final ScreenshotController screenshotController = ScreenshotController(); final int fileCount = await CollectionsService.instance.getFileCount(collection); @@ -334,3 +299,35 @@ Future shareAlbumLinkWithPlaceholder( ); } } + +/// required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383 +/// This returns the position of the share button if context and key are not null +/// and if not, it returns a default position so that the share sheet on iPad has +/// some position to show up. +Rect _sharePosOrigin(BuildContext? context, GlobalKey? key) { + late final Rect rect; + if (context != null) { + rect = shareButtonRect(context, key); + } else { + rect = const Offset(20.0, 20.0) & const Size(10, 10); + } + return rect; +} + +Future _createAlbumPlaceholder( + List files, + ScreenshotController screenshotController, + BuildContext context, +) async { + final Widget imageWidget = LinkPlaceholder( + files: files, + ); + final double pixelRatio = MediaQuery.devicePixelRatioOf(context); + final bytesOfImageToWidget = await screenshotController.captureFromWidget( + imageWidget, + pixelRatio: pixelRatio, + targetSize: MediaQuery.sizeOf(context), + delay: const Duration(milliseconds: 300), + ); + return bytesOfImageToWidget; +}