universal_html icon indicating copy to clipboard operation
universal_html copied to clipboard

Downloading image from website opened from mobile

Open 00AhmedMokhtar00 opened this issue 4 years ago • 0 comments

I'm trying to download an captured QR png image locally I need to achieve that for flutter web.

I found the solution: https://stackoverflow.com/a/67016194/11468643

which is working fine when I open the website from any laptop, but it doesn't work when I open the website from mobile (neither android nor ios) which is very weird!

Sample of my code

RenderRepaintBoundary? boundary =
      repaintGlobalKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
      ui.Image? image = await boundary?.toImage(pixelRatio: 3.0);
      ByteData? byteData = await image?.toByteData(format: ui.ImageByteFormat.png);
      Uint8List? pngBytes = byteData?.buffer.asUint8List();

      final base64data = base64Encode(pngBytes!);
      final html.AnchorElement a = html.AnchorElement(href: 'data:image/png;base64,$base64data');
       a.download = 'IMG.png';
       a.click();
       a.remove(); 

00AhmedMokhtar00 avatar Nov 22 '21 11:11 00AhmedMokhtar00