hm21 / pro_image_editor

The pro_image_editor is a Flutter widget designed for image editing within your application. It provides a flexible and convenient way to integrate image editing capabilities into your Flutter project.
https://hm21.github.io/pro_image_editor/
BSD 3-Clause "New" or "Revised" License
94 stars 59 forks source link

[Feature request] Fix sticker or text position #191

Closed ABedrock closed 4 weeks ago

ABedrock commented 4 weeks ago

Platforms

iOS

Description

Hey @hm21,

I'm planning to use this amazing package with a fixed template, where users can modify the content but not the position of stickers or text. I reviewed your documentation, but I couldn't find anything relevant to that. Could you please help me find a solution?

Why

No response

hm21 commented 4 weeks ago

To prevent interaction with the layers, you can use callbacks, as demonstrated below.

return ProImageEditor.network(
  _url,
  key: editorKey,
  callbacks: ProImageEditorCallbacks(
    mainEditorCallbacks: MainEditorCallbacks(
      onScaleStart: (value) {
        int selectedIndex = editorKey.currentState!.selectedLayerIndex;
        if (selectedIndex < 0) return;
        Layer layer = editorKey.currentState!.activeLayers[selectedIndex];

        /// Stop interaction
        if (layer.runtimeType == StickerLayerData ||
            layer.runtimeType == TextLayerData) {
          editorKey.currentState!.layerInteractionManager.onScaleEnd();
          editorKey.currentState!.selectedLayerIndex = -1;
        }

        /// If you want to do more deep checks if the user can move the 
        /// layer or not you can do it like below
        /// 
        /// var runtimeType = layer.runtimeType;
        /// if (runtimeType == PaintingLayerData) {
        ///   var paintLayer = layer as PaintingLayerData;
        /// } else if (runtimeType == TextLayerData) {
        ///   var textLayer = layer as TextLayerData;
        /// } else if (runtimeType == StickerLayerData) {
        ///   var stickerLayer = layer as StickerLayerData;
        /// } else if (runtimeType == EmojiLayerData) {
        ///   var emojiLayer = layer as EmojiLayerData;
        /// }
      },
    ),