How to share a file using flutter

前端 未结 7 1280
悲哀的现实
悲哀的现实 2021-02-07 09:43

I am wondering how to share a file in a flutter app?

I saw some old references to using Intents with mojo, but that no longer seems to be present. This seems like a sta

7条回答
  •  情深已故
    2021-02-07 10:18

    You can use the EsysFlutterShare Plugin. In version 1.0.0 you can share any file you like and its working on both, iOS and Android.

    Just put that in yout pubspec.yaml:

    dependencies:
      esys_flutter_share: ^1.0.0
    

    Import the lib:

    import 'package:esys_flutter_share/esys_flutter_share.dart';
    

    Share a file:

    final ByteData bytes = await rootBundle.load('assets/image1.png');
    await Share.file('esys image', 'esys.png', bytes.buffer.asUint8List(), 'image/png');
    

    You need to privide a title, a file name, the file-bytes and a mime type.

提交回复
热议问题