flutter 將視圖Widget 生成成Png 流程
將需要生成圖片的Widget 使用RepaintBoundary包裹起來,并給定globalkey。
通過globalKey獲取renderObject .轉成圖就好
RepaintBoundary(
key: PageManageUtil().generateKey(pageIndex),
child: _inheritedInfo.dmsStackViewFromMap[pageIndex],
)
RenderRepaintBoundary boundary = _pageGlobalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage(pixelRatio: 3.0);
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
Uint8List _uInt8List = byteData.buffer.asUint8List();
Image.memory(_uInt8List, width: 100, height: 177)