import 'dart:io'; import 'package:system_share/system_share.dart'; class SystemShareUtil { SystemShareUtil._(); static Future shareWechatFile(String filePath) async { if (Platform.isAndroid) { String wechatPackageName = 'com.tencent.mm'; //检查是否安装微信 bool isInstalled = await SystemShare.isInstalled(wechatPackageName); if (!isInstalled) { throw SystemShareException('未安装微信'); } SystemShare.shareFile(filePath, wechatPackageName, '分享到微信', shareFileType: 'text/*'); } } static Future shareQQFile(String filePath) async { if (Platform.isAndroid) { String qqPackageName = 'com.tencent.mobileqq'; //检查是否安装微信 bool isInstalled = await SystemShare.isInstalled(qqPackageName); if (!isInstalled) { throw SystemShareException('未安装QQ'); } SystemShare.shareFile(filePath, qqPackageName, '分享到QQ', shareFileType: 'text/*'); } } static Future isInstalled(String packageName) { return SystemShare.isInstalled(packageName); } } class SystemShareException implements Exception { final String message; SystemShareException(this.message); }