You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the QrPainter basically because I need the ui.Image to share the generated image with other apps. So, I'm not sure if I really must use that.
But, I saw that emptyColor is deprecated for QrPainter and it has the following comment:
You should us the background color value of your container widget
That would be the CustomPaint widget? Anyway the QrPainter does not offer the foregroundColor and backgroundColor as the QrImage. What would be the proper setup of the colour with QrPainter?
The text was updated successfully, but these errors were encountered:
However, a workaround to export the QrPainter as image is to use the QrDrawing (where there's a background and foreground attributes) within a GlobalKey and create the raw image based on that key. Something like:
Future<Uint8List> createImageFromRenderKey({GlobalKey<State<StatefulWidget>>? renderKey}) async {
try {
final RenderRepaintBoundary boundary = renderKey?.currentContext?.findRenderObject()! as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage(pixelRatio: 3);
final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
return byteData!.buffer.asUint8List();
} catch(_) {
rethrow;
}
}
createImageFromRenderKey is the method to be called on your "export" button created from:
final GlobalKey globalKey = GlobalKey();
The rethrow is a workaround to bypass Flutter's limitation/bug from flutter/flutter#22308 where the RepaintBoundary class may be being used when the UI is being rehydrated (exposed as boundary.debugNeedsPaint), causing an unhandled exception or creating a low-quality image. So if the UI is being painted at that time, I rethrow the method.
I'm using the
QrPainter
basically because I need theui.Image
to share the generated image with other apps. So, I'm not sure if I really must use that.But, I saw that
emptyColor
is deprecated forQrPainter
and it has the following comment:That would be the
CustomPaint
widget? Anyway theQrPainter
does not offer theforegroundColor
andbackgroundColor
as theQrImage
. What would be the proper setup of the colour withQrPainter
?The text was updated successfully, but these errors were encountered: