shareBlogEntry static method
Share a BlogEntry with optional thumbnail.
Implementation
static Future<void> shareBlogEntry(BlogEntry blogEntry) async {
// Format the blog content
String content = blogEntry.content;
String dotsLine = "";
for (int i = 0; i < blogEntry.profileName.length; i++) {
dotsLine = "$dotsLine.";
}
String formattedContent = "${blogEntry.title}\n\n$content\n\n${blogEntry.profileName}\n$dotsLine";
// Vanity URL: emxi.org/blog/{slug} or emxi.org/blog/{id}
String vanityUrl = DeeplinkUtilities.generateVanityUrl(
type: 'blog', slug: blogEntry.slug, id: blogEntry.id,
);
String sharedText = '$formattedContent\n\n'
'${MessageTranslationConstants.shareAppMsg.tr}\n\n'
'${AppTranslationConstants.explorePlatform.tr}: $vanityUrl';
List<XFile> sharedFiles = [];
if (!kIsWeb) {
final thumbnailLocalPath = await _getThumbnailPath(blogEntry.thumbnailUrl);
if (thumbnailLocalPath.isNotEmpty) {
sharedFiles.add(XFile(thumbnailLocalPath));
}
}
ShareResult 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,
);
}
}