Flutter - How to save a chart as image in device or send to server?

Viewed 796

I need to make a chart in Flutter with both line graph and point graph in one. I found that charts_flutter library allows 'combo' charts. But I couldn't find a way to save the chart as image in device or send to server. Has anyone faced this issue? I am also open to other libraries if they can perform both of these tasks of creating a combined graph and saving as image. Thank you!

1 Answers

get the render object of the widget with its global key

RenderRepaintBoundary boundary = _globalKey.currentContext.findRenderObject();

convert the render object to Image class

ui.Image image = await boundary.toImage(pixelRatio: 3.0);

get the byteData

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

get the Uints, this is the image you want to process save to disk or send it over to server

Uint8List pngBytes = byteData.buffer.asUint8List();
Related