shareProduct static method
Share a shop product (AppReleaseItem or ShopMerchItem) with vanity URL.
Implementation
static Future<void> shareProduct({
required String productId,
required String name,
required String imgUrl,
required double price,
required String ownerName,
String type = 'product', // 'product' for release, 'merch' for merch
}) async {
// Vanity URL: emxi.org/shop/{productId}
String vanityUrl = DeeplinkUtilities.generateVanityUrl(type: type, id: productId);
String priceText = '\$${price.toStringAsFixed(0)} MXN';
String sharedText = '$name\n'
'por $ownerName\n'
'$priceText\n\n'
'${MessageTranslationConstants.shareAppMsg.tr}\n\n'
'${AppTranslationConstants.explorePlatform.tr}: $vanityUrl';
List<XFile> sharedFiles = [];
if (!kIsWeb) {
final thumbnailLocalPath = await _getThumbnailPath(imgUrl, imgName: "${ownerName}_$name");
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,
);
}
}