captureEditorImage method

Future<Uint8List> captureEditorImage()

Captures the final editor image.

This method generates the final image of the editor content, taking into account the pixel ratio for high-resolution images. If generateOnlyImageBounds is set in imageGenerationConfigs, it uses the base pixel ratio; otherwise, it uses the maximum of the base pixel ratio and the device's pixel ratio.

Returns a Uint8List representing the final image.

Returns an empty Uint8List if the screenshot capture fails.

Implementation

Future<Uint8List> captureEditorImage() async {
  if (_isEditorOpen) {
    Navigator.pop(context);
    if (!_pageOpenCompleter.isCompleted) await _pageOpenCompleter.future;
    if (!mounted) return Uint8List.fromList([]);
  }

  if (_imageInfos == null) await _decodeImage();

  if (!mounted) return Uint8List.fromList([]);

  return await _controllers.screenshot.captureFinalScreenshot(
        imageInfos: _imageInfos!,
        backgroundScreenshot: _stateManager.position > 0
            ? _stateManager.activeScreenshot
            : null,
        originalImageBytes: _stateManager.position > 0
            ? null
            : await _image.safeByteArray(context),
      ) ??
      Uint8List.fromList([]);
}