Actually you do not need to paste the image into the TextField, you can wrap the Image area and TextField into a Container/Column which looks like a TextField, make sure to change background of everything to match TextField background.
Column(Children: [ImageArea(), TextField()])
Then enable the paste action in context menu and for ctrl+v
action.
To make paste always show in context menu (by default it only shows when you have text in clipboard, not images):
TextField(contextMenuBuilder: (BuildContext context, EditableTextState state) {
final List<ContextMenuButtonItem> buttonItems =
state.contextMenuButtonItems;
final pasteButton = buttonItems
.firstWhereOrNull((x) => x.type == ContextMenuButtonType.paste);
if (pasteButton == null) {
buttonItems.add(ContextMenuButtonItem(
onPressed: () {
// read clipboard using pasteboard or super_clipboard etc.
},
type: ContextMenuButtonType.paste,
));
}
return AdaptiveTextSelectionToolbar.buttonItems(
anchors: state.contextMenuAnchors,
buttonItems: buttonItems,
);
})
To make ctrl + v
work:
TextField(focusNode: FocusNode(
onKeyEvent: (node, event) {
// Check if 'V' key is pressed
bool isVKeyPressed = (event.physicalKey == PhysicalKeyboardKey.keyV);
// Check if 'Ctrl' or 'Meta' key is pressed
bool isCtrlOrMetaPressed =
HardwareKeyboard.instance.physicalKeysPressed.any(
(key) =>
key == PhysicalKeyboardKey.controlLeft ||
key == PhysicalKeyboardKey.controlRight ||
key == PhysicalKeyboardKey.metaLeft ||
key == PhysicalKeyboardKey.metaRight,
);
// Only trigger paste action if both 'V' and 'Ctrl/Meta' keys are pressed
if (isVKeyPressed && isCtrlOrMetaPressed) {
handlePaste();
}
},
);)