toImageBytes static method

Future<Uint8List?> toImageBytes(
  1. GlobalKey<State<StatefulWidget>> key, {
  2. ChartImageExportFormat format = ChartImageExportFormat.png,
  3. double pixelRatio = 2.0,
  4. int jpegQuality = 90,
  5. Color jpegBackgroundColor = Colors.white,
})

Capture the widget attached to key in the requested image format.

Implementation

static Future<Uint8List?> toImageBytes(
  GlobalKey key, {
  ChartImageExportFormat format = ChartImageExportFormat.png,
  double pixelRatio = 2.0,
  int jpegQuality = 90,
  Color jpegBackgroundColor = Colors.white,
}) {
  return switch (format) {
    ChartImageExportFormat.png => toPng(key, pixelRatio: pixelRatio),
    ChartImageExportFormat.jpeg => toJpeg(
      key,
      pixelRatio: pixelRatio,
      quality: jpegQuality,
      backgroundColor: jpegBackgroundColor,
    ),
  };
}