dint-dev / universal_html

Cross-platform 'dart:html'.
https://pub.dev/packages/universal_html
Apache License 2.0
201 stars 63 forks source link

Downloading image from website opened from mobile #61

Closed 00AhmedMokhtar00 closed 1 year ago

00AhmedMokhtar00 commented 2 years ago

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(); 
terrier989 commented 1 year ago

The package is not meant for data conversions like that.