2022年6月28日星期二

Flutter how to share image on assets folder?

 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();
      file.writeAsBytesSync(list);


Then use share package to share it, should work;



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

沒有留言:

發佈留言