Flutter 生成图片分享

class PlaceShareBit{

///加载分享截图

Future loadShareBitmap( GlobalKey getShareKey,{double pixelRatio = 3.0}) async {

try {

if(getShareKey == null){

return null;

}

RenderRepaintBoundary boundary =

getShareKey.currentContext.findRenderObject() as RenderRepaintBoundary;

var image = await boundary.toImage(pixelRatio: pixelRatio);

ByteData bytes = await image.toByteData(format: ui.ImageByteFormat.png);

var pngBytes = bytes?.buffer.asUint8List();

return pngBytes;

} catch (e) {

print(e);

}

return null;

}

}

在需要分享的widget 处使用gloablekey,

// StreamBuilder(

// stream: listVM.shareStream,

// builder: (context,snapShot){

// if(snapShot.data == null){

// return Container();

// }

// r

你可能感兴趣的:(Flutter,flutter,vue.js,前端)