tencent cloud

Tencent Cloud Super App as a Service

Customizing the Sharing Capability

Download
Focus Mode
Font Size
Last updated: 2025-07-04 16:48:08
Developers can customize the buttons on the operation panel of the mini program, including the share button and other buttons. Currently, you can access the operation panel by tapping the "More" button in the upper right corner of the mini program.
@override
Future<List<CustomMenu>> getCustomMenus() async {
CustomMenu menu1 = CustomMenu(
100, 'res/images/tcmpp_demo_share_whatsapp.jpeg', 'WhatsApp', true,shareKey: "whatsapp");
CustomMenu menu2 = CustomMenu(
101,
'res/images/tcmpp_demo_share_more.png',
'Custom',
false);

return [
menu1,
menu2,
];
}
Developers can also customize the share list displayed in wx.showShareImageMenu by overriding the getImageShareCustomMenus method:
@override
Future<List<CustomMenu>> getImageShareCustomMenus() async {
CustomMenu menu1 = CustomMenu(200, '', 'Share To Friend', true);
CustomMenu menu2 = CustomMenu(201, '', 'Share To WhatsApp', true);

return [menu1, menu2];
}
Menu tap callback:
@override
Future<void> customMenuClick(int menuId, ShareData? shareMenu) async {
print("click menuId:$menuId shareMenu:$shareMenu");
Fluttertoast.showToast(msg: "click menuId:$menuId");

if (menuId == 101) {
// System share
String text = "This is the content to share:${shareMenu?.appTitle}";
await Share.share(text);
return;
}

if (menuId == 100) {
// Share to WhatsApp
String text = "This is the content to share${shareMenu?.appTitle}";
String whatsappUrl = "whatsapp://send?text=$text";
if (await canLaunchUrl(Uri.parse(whatsappUrl))) {
await launchUrl(Uri.parse(whatsappUrl));
} else {
await Share.share(text);
}
return;
}

if (menuId == 200) {
final imageUrl = shareMenu?.imageUrl;
if (imageUrl != null && imageUrl.isNotEmpty) {
await Share.shareXFiles([XFile(imageUrl)], text: "Share image");

final appId = shareMenu?.appId;
if(appId != null && appId.isNotEmpty) {
TcmppFlutter().moveMiniAppToFront(appId);
}

} else {
Fluttertoast.showToast(msg: "Image url not found");
}
return;
} else if(menuId == 201) {
Fluttertoast.showToast(msg: "Share to WhatsApp");
}
}



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback