Flutter:如何将 PDF 文件共享到内置应用程序,例如 Whatsapp 或电子邮件

Alv*_*yil 2 share file flutter

我正在开发一个产品信息应用程序,我需要分享产品的规格PDF,有什么办法可以做到。我使用了这个包,share_extend但在使用这个包时出现异常

E/flutter (11283): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method share on channel com.zt.shareextend/share_extend)
E/flutter (11283): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)

Run Code Online (Sandbox Code Playgroud)

这是我的代码

Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        tooltip: 'Share File',
        onPressed: () async {


          var dir = await getApplicationDocumentsDirectory();
          File file = File('${dir.path}/${widget.product}.pdf');

          if (!await file.exists()) {
            await file.create(recursive: true);
            file.writeAsStringSync("test for share documents file");
          }

          ShareExtend.share(file.path, "file");


        },
        backgroundColor: Color(0xffECECEC),
        child: Icon(
          Icons.share,
          color: Color(0xff6F6F6F),
          size: 30.0,
        ),
      ),);
}
Run Code Online (Sandbox Code Playgroud)

GMa*_*zke 5

您现在可以使用Share 插件来做到这一点!

前任:

Share.shareFiles(['${directory.path}/yourPdf.pdf'], text: 'Your PDF!');
Run Code Online (Sandbox Code Playgroud)