【发布时间】:2021-04-14 01:34:36
【问题描述】:
我正在尝试使用RenderRepaintBoundary 生成图像并希望将图像保存在我的本地目录中。
我可以保存图像,但我得到的是黑色图像而不是 QR 图像。
我将图像写入目录的代码块:
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);
}
正在生成二维码的代码块:
RepaintBoundary( key: globalKey,child: QrImage(data: _dataString,size: 0.3 * bodyHeight,), );
【问题讨论】:
标签: flutter dart flutter-layout dart-pub