shareAppWithPost static method
Future<void>
shareAppWithPost(
- Post post
)
Implementation
static Future<void> shareAppWithPost(Post post) async {
String thumbnailLocalPath = "";
if(post.thumbnailUrl.isNotEmpty || post.mediaUrl.isNotEmpty ) {
String imgUrl = post.thumbnailUrl.isNotEmpty ? post.thumbnailUrl : post.mediaUrl;
if(imgUrl.isNotEmpty) {
thumbnailLocalPath = await FileDownloader.downloadImage(imgUrl);
}
}
ShareResult? shareResult;
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";
}
String sharedText = '$caption${caption.isNotEmpty ? "\n\n" : ""}'
'${MessageTranslationConstants.shareAppMsg.tr}\n'
'\n${AppProperties.getLinksUrl()}\n';
List<XFile> sharedFiles = [];
if(thumbnailLocalPath.isNotEmpty) {
sharedFiles.add(XFile(thumbnailLocalPath));
}
shareResult = await SharePlus.instance.share(
ShareParams(text: sharedText, files: sharedFiles)
);
if(shareResult.status == ShareResultStatus.success && shareResult.raw != "null") {
Get.snackbar(MessageTranslationConstants.sharedApp.tr,
MessageTranslationConstants.sharedAppMsg.tr,
snackPosition: SnackPosition.bottom);
}
}