我希望能够在单击电子邮件时打开共享表(包含所有共享选项)。它是预先填写的。应该预先填写目标电子邮件。
static Future<void> exportFile({
required BuildContext context,
required String filename,
required List<int> bytes,
String? text,
String? subject
}) async {
// This box is for sharePositionOrigin. This is the part that is needed for iPad. It does not affect any other devices.
final box = context.findRenderObject() as RenderBox?;
// Generate a String with the path.
final directory = await getTemporaryDirectory();
String filePath = '${directory.path}/$filename';
// Generate the file.
final file = File(filePath);
// Let the callback write data to the file.
await file.writeAsBytes(bytes, flush: true);
// Share the newly created file. The values that are passed to parameters "text" and "subject" are
// used in emails.
await Share.shareXFiles(
[XFile(file.path)],
text: text,
subject: subject,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size
);
}
这不会预填充目标电子邮件,但仅预填充主题和文本。 有什么想法吗?
试试这个
String mailtoLink = 'mailto:$email?subject=${Uri.encodeComponent(subject ?? '')}&body=${Uri.encodeComponent(text ?? '')}';
await Share.shareXFiles(
[XFile(file.path)],
email:mailtoLink,
text: text,
subject: subject,
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size
);