From 3d0a810f262aeff72e0cb0d8ebba4f92ae361b4f Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 4 Jun 2024 12:11:04 +0530 Subject: [PATCH] [mob][photos] Upgrade share_plus --- mobile/lib/utils/share_util.dart | 36 +++++++++++++++----------------- mobile/pubspec.lock | 8 +++---- mobile/pubspec.yaml | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/mobile/lib/utils/share_util.dart b/mobile/lib/utils/share_util.dart index 57e2a68fa5..91dc292fad 100644 --- a/mobile/lib/utils/share_util.dart +++ b/mobile/lib/utils/share_util.dart @@ -18,19 +18,8 @@ import 'package:share_plus/share_plus.dart'; import "package:uuid/uuid.dart"; final _logger = Logger("ShareUtil"); -// Set of possible image extensions -final _imageExtension = {"jpg", "jpeg", "png", "heic", "heif", "webp", ".gif"}; -final _videoExtension = { - "mp4", - "mov", - "avi", - "mkv", - "webm", - "wmv", - "flv", - "3gp", -}; -// share is used to share media/files from ente to other apps + +/// share is used to share media/files from ente to other apps Future share( BuildContext context, List files, { @@ -62,9 +51,13 @@ Future share( final paths = await Future.wait(pathFutures); await dialog.hide(); paths.removeWhere((element) => element == null); - final List nonNullPaths = paths.map((element) => element!).toList(); - return Share.shareFiles( - nonNullPaths, + final xFiles = []; + for (String? path in paths) { + if (path == null) continue; + xFiles.add(XFile(path)); + } + await Share.shareXFiles( + xFiles, // required for ipad https://github.com/flutter/flutter/issues/47220#issuecomment-608453383 sharePositionOrigin: shareButtonRect(context, shareButtonKey), ); @@ -99,8 +92,10 @@ Rect shareButtonRect(BuildContext context, GlobalKey? shareButtonKey) { ); } -Future shareText(String text) async { - return Share.share(text); +Future shareText(String text) async { + return Share.shareUri( + Uri.parse(text), + ); } Future> convertIncomingSharedMediaToFile( @@ -223,5 +218,8 @@ Future shareImageAndUrl( String imagePath, String url, ) async { - await Share.shareXFiles([XFile(imagePath)], text: url); + await Share.shareXFiles( + [XFile(imagePath)], + text: url, + ); } diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index edad689d58..e2408583c4 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -1907,18 +1907,18 @@ packages: dependency: "direct main" description: name: share_plus - sha256: "3ef39599b00059db0990ca2e30fca0a29d8b37aae924d60063f8e0184cf20900" + sha256: ef3489a969683c4f3d0239010cc8b7a2a46543a8d139e111c06c558875083544 url: "https://pub.dev" source: hosted - version: "7.2.2" + version: "9.0.0" share_plus_platform_interface: dependency: transitive description: name: share_plus_platform_interface - sha256: "251eb156a8b5fa9ce033747d73535bf53911071f8d3b6f4f0b578505ce0d4496" + sha256: "0f9e4418835d1b2c3ae78fdb918251959106cefdbc4dd43526e182f80e82f6d4" url: "https://pub.dev" source: hosted - version: "3.4.0" + version: "4.0.0" shared_preferences: dependency: "direct main" description: diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index c5a1471771..5dccd03b49 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -145,7 +145,7 @@ dependencies: scrollable_positioned_list: ^0.3.5 sentry: ^7.9.0 sentry_flutter: ^7.9.0 - share_plus: 7.2.2 + share_plus: ^9.0.0 shared_preferences: ^2.0.5 simple_cluster: ^0.3.0 sqflite: ^2.3.0