done method
Handles the crop image operation.
Implementation
Future<void> done() async {
if (_interactionActive) return;
_interactionActive = true;
initConfigs.onImageEditingStarted?.call();
TransformConfigs transformC =
!canRedo && !canUndo && transformConfigs != null
? transformConfigs!
: activeHistory;
_showFakeHero = enableFakeHero;
_fakeHeroTransformConfigs = transformC;
_updateAllStates();
if (!initConfigs.convertToUint8List) {
List<Layer> updatedLayers = LayerTransformGenerator(
layers: initConfigs.layers ?? [],
activeTransformConfigs:
initConfigs.transformConfigs ?? TransformConfigs.empty(),
newTransformConfigs: transformC,
layerDrawAreaSize: originalSize,
fitToScreenFactor: _transformHelperScale,
undoChanges: false,
).updatedLayers;
_layers = updatedLayers;
_updateAllStates();
await initConfigs.onDone?.call(transformC, _transformHelperScale);
if (mounted) Navigator.pop(context, transformC);
} else {
LoadingDialog loading = LoadingDialog();
await loading.show(
context,
configs: configs,
theme: theme,
message: i18n.doneLoadingMsg,
);
if (imageInfos == null) {
await setImageInfos(activeHistory: activeHistory);
}
if (!mounted) return;
Uint8List? bytes = await screenshotCtrl.captureFinalScreenshot(
imageInfos: imageInfos!,
context: context,
widget: _screenshotWidget(transformC),
targetSize:
_rotated90deg ? imageInfos!.rawSize.flipped : imageInfos!.rawSize,
backgroundScreenshot:
screenshotHistoryPosition >= screenshotHistory.length
? null
: screenshotHistory[screenshotHistoryPosition],
);
await initConfigs.onImageEditingComplete
?.call(bytes ?? Uint8List.fromList([]));
if (mounted) loading.hide(context);
initConfigs.onCloseEditor?.call();
}
cropRotateEditorCallbacks?.handleDone();
_interactionActive = false;
}