openStickerEditor method

void openStickerEditor()

Opens the sticker editor as a modal bottom sheet.

Implementation

void openStickerEditor() async {
  setState(() => _layerInteractionManager.selectedLayerId = '');
  ServicesBinding.instance.keyboard.removeHandler(_onKeyEvent);
  final effectiveBoxConstraints = imageEditorTheme
          .stickerEditor.editorBoxConstraintsBuilder
          ?.call(context, configs) ??
      imageEditorTheme.editorBoxConstraintsBuilder?.call(context, configs);
  var sheetTheme = imageEditorTheme.stickerEditor.themeDraggableSheet;
  StickerLayerData? layer = await showModalBottomSheet(
      context: context,
      backgroundColor:
          imageEditorTheme.stickerEditor.bottomSheetBackgroundColor,
      constraints: effectiveBoxConstraints,
      showDragHandle: imageEditorTheme.stickerEditor.showDragHandle,
      isScrollControlled: true,
      useSafeArea: true,
      builder: (_) {
        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 StickerEditor(
              configs: configs,
              scrollController: controller,
            );
          },
        );
      });
  ServicesBinding.instance.keyboard.addHandler(_onKeyEvent);
  if (layer == null || !mounted) return;
  layer.offset = newLayerOffsetPosition;

  addLayer(layer);

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