shareAppWithPost static method
Future<void>
shareAppWithPost(
- Post post
)
Implementation
static Future<void> shareAppWithPost(Post post) async {
String caption = post.caption;
if(post.type == PostType.blogEntry) {
if(caption.contains(CoreConstants.titleTextDivider)) {
caption = caption.replaceAll(CoreConstants.titleTextDivider, "\n\n");
}
String dotsLine = "";
for(int i = 0; i < post.profileName.length; i++) {
dotsLine = "$dotsLine.";
}
caption = "$caption\n\n${post.profileName}\n$dotsLine";
}
// Vanity URL: emxi.org/p/{postId}
String vanityUrl = DeeplinkUtilities.generateVanityUrl(type: 'post', id: post.id);
String sharedText = '$caption${caption.isNotEmpty ? "\n\n" : ""}'
'${MessageTranslationConstants.shareAppMsg.tr}\n\n'
'${AppTranslationConstants.explorePlatform.tr}: $vanityUrl';
// On web: share text only (no file system access).
// On mobile: download thumbnail and attach it.
List<XFile> sharedFiles = [];
if (!kIsWeb) {
final thumbnailLocalPath = await _getThumbnailPath(
post.thumbnailUrl.isNotEmpty ? post.thumbnailUrl : post.mediaUrl,
);
if (thumbnailLocalPath.isNotEmpty) {
sharedFiles.add(XFile(thumbnailLocalPath));
}
}
final shareResult = await SharePlus.instance.share(
ShareParams(
text: sharedText,
files: sharedFiles.isNotEmpty ? sharedFiles : null,
previewThumbnail: sharedFiles.isNotEmpty ? sharedFiles.first : null,
uri: kIsWeb ? Uri.tryParse(vanityUrl) : null,
)
);
if(shareResult.status == ShareResultStatus.success && (shareResult.raw) != "null") {
Sint.snackbar(MessageTranslationConstants.sharedApp.tr,
MessageTranslationConstants.sharedAppMsg.tr,
snackPosition: SnackPosition.bottom);
}
}