openEmojiEditor method

void openEmojiEditor()

Opens the emoji editor.

This method opens the emoji editor as a modal bottom sheet, allowing the user to add emoji layers to the current image. The selected emoji layer's properties, such as scale and offset, are adjusted before adding it to the image's layers.

Keyboard event handlers are temporarily removed while the emoji editor is active and restored after its closure.

Implementation

void openEmojiEditor() async {
  setState(() => layerInteractionManager.selectedLayerId = '');
  _checkInteractiveViewer();
  ServicesBinding.instance.keyboard.removeHandler(_onKeyEvent);
  final effectiveBoxConstraints = imageEditorTheme
          .emojiEditor.editorBoxConstraintsBuilder
          ?.call(context, configs) ??
      imageEditorTheme.editorBoxConstraintsBuilder?.call(context, configs);

  ThemeDraggableSheet sheetTheme =
      imageEditorTheme.emojiEditor.themeDraggableSheet;
  bool useDraggableSheet = sheetTheme.maxChildSize != sheetTheme.minChildSize;
  EmojiLayerData? layer = await showModalBottomSheet(
      context: context,
      backgroundColor: imageEditorTheme.emojiEditor.backgroundColor,
      constraints: effectiveBoxConstraints,
      showDragHandle: imageEditorTheme.emojiEditor.showDragHandle,
      isScrollControlled: true,
      useSafeArea: true,
      builder: (BuildContext context) {
        if (!useDraggableSheet) {
          return ConstrainedBox(
            constraints: effectiveBoxConstraints ??
                BoxConstraints(
                    maxHeight:
                        300 + MediaQuery.of(context).viewInsets.bottom),
            child: EmojiEditor(configs: configs),
          );
        }

        return DraggableScrollableSheet(
            expand: sheetTheme.expand,
            initialChildSize: sheetTheme.initialChildSize,
            maxChildSize: sheetTheme.maxChildSize,
            minChildSize: sheetTheme.minChildSize,
            shouldCloseOnMinExtent: sheetTheme.shouldCloseOnMinExtent,
            snap: sheetTheme.snap,
            snapAnimationDuration: sheetTheme.snapAnimationDuration,
            snapSizes: sheetTheme.snapSizes,
            builder: (_, controller) {
              return EmojiEditor(
                configs: configs,
                scrollController: controller,
              );
            });
      });
  ServicesBinding.instance.keyboard.addHandler(_onKeyEvent);
  if (layer == null || !mounted) return;
  layer.scale = emojiEditorConfigs.initScale;

  addLayer(layer);

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