how to save my QR generated image into gallery? using Flutter
377
This is caused by having transparent background; Simple solution is to wrap your QrImage with Container that has white backround:
Container(
color: Colors.white,
child: QrImage(....
)
Author by
Jayesh Choudhary
Updated on December 26, 2022Comments
-
Jayesh Choudhary over 1 year
I am trying to generate an image using
RenderRepaintBoundary
and want to save the image in my local directory.
I am able to save the image but I get a black image instead of a QR image.Code block where I am writing the image to the directory:
try { RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject(); var image = await boundary.toImage(); ByteData byteData = await image.toByteData(format: ImageByteFormat.png); Uint8List pngBytes = byteData.buffer.asUint8List(); final file = await new File('/<localpath>/image.png').create(); await file.writeAsBytes(pngBytes); } catch (e) { print(e); }
Code block where QR code is being generated:
RepaintBoundary( key: globalKey,child: QrImage(data: _dataString,size: 0.3 * bodyHeight,), );