takeScreenshot method

  1. @override
void takeScreenshot()
override

Takes a screenshot of the current editor state.

Implementation

@override
void takeScreenshot() async {
  if (!widget.initConfigs.convertToUint8List) return;

  await setImageInfos(activeHistory: activeHistory, forceUpdate: true);
  // Capture the screenshot in a post-frame callback to ensure the UI is fully rendered.
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    if (transformConfigs == null &&
        history.length == 1 &&
        history.first.isEmpty) {
      setInitHistory(
        TransformConfigs(
          angle: rotateAnimation.value,
          cropRect: cropRect,
          originalSize: originalSize,
          cropEditorScreenRatio: cropEditorScreenRatio,
          scaleUser: userScaleFactor,
          scaleRotation: scaleAnimation.value,
          aspectRatio: aspectRatio,
          flipX: flipX,
          flipY: flipY,
          offset: translate,
        ),
      );
    }

    TransformConfigs transformC =
        !canRedo && !canUndo && transformConfigs != null
            ? transformConfigs!
            : activeHistory;

    screenshotCtrl.captureImage(
      imageInfos: imageInfos!,
      screenshots: screenshotHistory,
      targetSize:
          _rotated90deg ? imageInfos!.rawSize.flipped : imageInfos!.rawSize,
      widget: _screenshotWidget(transformC),
    );
  });
}