captureFromWidget method

Future<Uint8List?> captureFromWidget(
  1. Widget widget, {
  2. required ImageInfos imageInfos,
  3. Size? targetSize,
  4. OutputFormat? format,
  5. dynamic onImageCaptured(
    1. Image?
    )?,
  6. bool stateHistroyScreenshot = false,
  7. String? id,
})

Capture an invisible widget.

Implementation

Future<Uint8List?> captureFromWidget(
  Widget widget, {
  required ImageInfos imageInfos,
  Size? targetSize,
  OutputFormat? format,
  Function(ui.Image?)? onImageCaptured,
  bool stateHistroyScreenshot = false,
  String? id,
}) async {
  recordReadyHelper = Completer();
  recorderStream.add(
    SizedBox(
      width: targetSize?.width,
      height: targetSize?.height,
      child: FittedBox(
        fit: BoxFit.contain,
        child: widget,
      ),
    ),
  );

  /// Ensure the recorder is ready
  if (!recordReadyHelper.isCompleted) {
    await recordReadyHelper.future;
  }
  ui.Image? image = await _getRenderedImage(
    imageInfos: imageInfos,
    useThumbnailSize: false,
    widgetKey: recorderKey,
  );

  recorderStream.add(null);

  return _capture(
    image: image,
    imageInfos: imageInfos,
    id: id,
    onImageCaptured: onImageCaptured,
    stateHistroyScreenshot: stateHistroyScreenshot,
    outputFormat: format,
  );
}