showImageMenu function

void showImageMenu(
  1. OverlayState container,
  2. EditorState editorState,
  3. SelectionMenuService menuService, {
  4. OnInsertImage? onInsertImage,
})

Implementation

void showImageMenu(
  OverlayState container,
  EditorState editorState,
  SelectionMenuService menuService, {
  OnInsertImage? onInsertImage,
}) {
  menuService.dismiss();

  final (left, top, right, bottom) = menuService.getPosition();

  late final OverlayEntry imageMenuEntry;

  void insertImage(
    String url,
  ) {
    if (onInsertImage != null) {
      onInsertImage(url);
    } else {
      editorState.insertImageNode(url);
    }
    menuService.dismiss();
    imageMenuEntry.remove();
    keepEditorFocusNotifier.decrease();
  }

  keepEditorFocusNotifier.increase();
  imageMenuEntry = FullScreenOverlayEntry(
    left: left,
    right: right,
    top: top,
    bottom: bottom,
    dismissCallback: () => keepEditorFocusNotifier.decrease(),
    builder: (context) => UploadImageMenu(
      backgroundColor: menuService.style.selectionMenuBackgroundColor,
      headerColor: menuService.style.selectionMenuItemTextColor,
      unselectedLabelColor: menuService.style.selectionMenuUnselectedLabelColor,
      dividerColor: menuService.style.selectionMenuDividerColor,
      urlInputBorderColor: menuService.style.selectionMenuLinkBorderColor,
      urlInvalidLinkColor: menuService.style.selectionMenuInvalidLinkColor,
      uploadButtonColor: menuService.style.selectionMenuButtonColor,
      uploadButtonBorderColor: menuService.style.selectionMenuButtonBorderColor,
      uploadButtonTextColor: menuService.style.selectionMenuButtonTextColor,
      tabIndicatorColor: menuService.style.selectionMenuTabIndicatorColor,
      uploadIconColor: menuService.style.selectionMenuButtonIconColor,
      width: MediaQuery.of(context).size.width * 0.3,
      onSubmitted: insertImage,
      onUpload: insertImage,
    ),
  ).build();
  container.insert(imageMenuEntry);
}