Flutter how to share image on assets folder?


With this code I keep getting the error "ENOENT (No such file or directory), null, null, null)". How can I share a file on the assets folder?

Directory directory = await getApplicationDocumentsDirectory();
    Share.shareFiles(['${directory.path}/baws.png'], text: 'Great picture');


First get your image as bytes and copy to temp file.

      final bytes = await rootBundle.load('assets/image.jpg');
      final list = bytes.buffer.asUint8List();

      final tempDir = await getTemporaryDirectory();
      final file = await File('${tempDir.path}/image.jpg').create();

Then use share package to share it, should work;

Share.shareFiles(['${file.path}'], text: 'Great picture');

Answered By – Muhtar

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *