openWhatsAppStickerEditor method

void openWhatsAppStickerEditor()

Opens the WhatsApp sticker editor.

This method removes the keyboard handler, then depending on the design mode specified in the configs parameter of the widget, it either opens the WhatsAppStickerPage directly or shows it as a modal bottom sheet.

If the design mode is set to ImageEditorDesignModeE.material, the WhatsAppStickerPage is opened directly using _openPage(). Otherwise, it is displayed as a modal bottom sheet with specific configurations such as transparent background, black barrier color, and controlled scrolling.

After the page is opened and a layer is returned, the keyboard handler is added back. If no layer is returned or the widget is not mounted, the method returns early.

If the returned layer's runtime type is not StickerLayerData, the layer's scale is set to the initial scale specified in emojiEditorConfigs of the configs parameter. Regardless, the layer's offset is set to the center of the image.

Finally, the layer is added, the UI is updated, and the widget's onUpdateUI callback is called if provided.

Implementation

void openWhatsAppStickerEditor() async {
  ServicesBinding.instance.keyboard.removeHandler(_onKeyEvent);

  Layer? layer;
  if (isMaterial) {
    layer = await _openPage(WhatsAppStickerPage(
      configs: configs,
    ));
  } else {
    final effectiveBoxConstraints = imageEditorTheme
            .stickerEditor.whatsAppEditorBoxConstraintsBuilder
            ?.call(context, configs) ??
        imageEditorTheme.stickerEditor.editorBoxConstraintsBuilder
            ?.call(context, configs) ??
        imageEditorTheme.editorBoxConstraintsBuilder?.call(context, configs);
    layer = await showModalBottomSheet(
      context: context,
      backgroundColor: Colors.transparent,
      barrierColor: Colors.black12,
      constraints: effectiveBoxConstraints,
      showDragHandle: false,
      isScrollControlled: true,
      useSafeArea: true,
      builder: (context) {
        return Padding(
          padding: const EdgeInsets.only(top: 12.0),
          child: ClipRRect(
            borderRadius: const BorderRadius.only(
              topLeft: Radius.circular(16),
              topRight: Radius.circular(16),
            ),
            clipBehavior: Clip.hardEdge,
            child: WhatsAppStickerPage(
              configs: configs,
            ),
          ),
        );
      },
    );
  }

  ServicesBinding.instance.keyboard.addHandler(_onKeyEvent);
  if (layer == null || !mounted) {
    setState(() {});
    return;
  }

  if (layer.runtimeType != StickerLayerData) {
    layer.scale = emojiEditorConfigs.initScale;
  }
  layer.offset = newLayerOffsetPosition;

  addLayer(layer);

  setState(() {});
  mainEditorCallbacks?.handleUpdateUI();
}