Flutter:如何将PDF文件共享给诸如Whatsapp或电子邮件之类的内置应用程序

时间:2019-11-15 20:56:59

标签: file flutter share

我正在开发产品信息应用程序,我需要共享产品的规格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)

这是我的代码

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,
        ),
      ),);
}

1 个答案:

答案 0 :(得分:2)

您现在可以使用Share plugin来这样做!

例如:

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