Closed Pratik-1620 closed 3 weeks ago
Mostly the reason is that people add the sticker before the editor is completely initialized which will make problem to capture the sticker in the background task correctly. Can you post your code from your editor so that I can check what exactly the problem is and what you need to change.
This issue is stale because it has been open for 3 days with no activity.
This issue was closed because it has been inactive for 5 days since being marked as stale.
This a current problem, i insert the image as a layer on the onAfterViewInit, as i pass the image as parameter to the widget, and if i made no modifications i only get the background color i made, no image layer appearing, but if a make some movements or editing the layer image is there.
Code:
mainEditorCallbacks: MainEditorCallbacks(
onAfterViewInit: () async {
if (widget.isReupload) {
// Add the image layer only after the editor is fully initialized
await _addImageLayer(widget.reuploadPath,
isNetworkImage: true);
} else {
// Add the image layer for newly uploaded images
await _addImageLayer(widget.image!.bytes!);
}
},
),
Function called:
Future<void> _addImageLayer(dynamic imageSource, {bool isNetworkImage = false}) async {
if (editorKey.currentState != null) {
// Ensure the editor is initialized and no duplicate layers are added
if (editorKey.currentState!.activeLayers.isEmpty) {
editorKey.currentState!.addLayer(
StickerLayerData(
offset: Offset.zero,
scale: _initScale,
sticker: GestureDetector(
onTap: () {
// Open the text editor when the image layer is tapped
editorKey.currentState!.openTextEditor();
},
child: isNetworkImage
? Image.network(
imageSource,
width: _editorSize.width,
height: _editorSize.height,
fit: BoxFit.contain,
)
: Image.memory(
imageSource,
width: _editorSize.width,
height: _editorSize.height,
fit: BoxFit.contain,
),
),
),
);
}
}
}
Your implementation of onAfterViewInit
appears to be correct. However, it appears that you haven't pre-cached the image, which is essential for ensuring that the editor can properly capture it. I recommend updating your _addImageLayer
method like below:
Future<void> _addImageLayer(
dynamic imageSource, {
bool isNetworkImage = false,
}) async {
if (editorKey.currentState != null) {
// Ensure the editor is initialized and no duplicate layers are added
if (editorKey.currentState!.activeLayers.isEmpty) {
/// Precache the image
await precacheImage(
isNetworkImage ? NetworkImage(imageSource) : MemoryImage(imageSource),
context,
size: _editorSize,
);
editorKey.currentState!.addLayer(
StickerLayerData(
offset: Offset.zero,
scale: _initScale,
sticker: GestureDetector(
onTap: () {
// Open the text editor when the image layer is tapped
editorKey.currentState!.openTextEditor();
},
child: isNetworkImage
? Image.network(
imageSource,
width: _editorSize.width,
height: _editorSize.height,
fit: BoxFit.contain,
)
: Image.memory(
imageSource,
width: _editorSize.width,
height: _editorSize.height,
fit: BoxFit.contain,
),
),
),
);
}
}
}
You can also check out this example which does exactly what you need.
It worked, thank you so much for your help!.
Package Version
5.3.0
Flutter Version
3.24.2
Platforms
Android, iOS
How to reproduce?
Thank you for the excellent package! I've integrated it into my project but encountered the following issue:
Expected Behavior: When the user navigates to the editor screen with a pre-added sticker and saves without any interaction (e.g., moving or resizing the sticker), the sticker should still be included in the saved image.
Please refer below images for your reference: