0

This is my current requirement:
A) The screenshot/bitmap in my clipboard must be pasted into the app (Platform: primarily Windows, but must run on all other platforms aswell: Android/iOS/Linux/MacOS/Web)

I found out that Flutter does not support anything else than plain text from the clipboard and a request for image/binary extraction is requested by the community.

That's a bummer, but then I remembered that Flutter supports ffi:

Flutter mobile can use the dart:ffi library to call native C APIs. FFI stands for foreign function interface. Other terms for similar functionality include native interface and language bindings.

That means I can write a custom or already existing C/C++ program to handle that use case and send it to flutter. However, it seems that C/C++ programs are not guaranteed to run everywhere (Android/iOS/Linux/Windows/MacOS/Web).

So, well, my conclusion is that if I want to fulfill that requirement, I basically need to write a C/C++ program for every platform.

That sounds troublesome, isn't there anything like a standardized method on all platforms to get dynamic data out of the clipboard? So that my Flutter application handles the logic?

Richard Heap
  • 48,344
  • 9
  • 130
  • 112
Marwin Lebensky
  • 270
  • 1
  • 2
  • 16
  • 1
    There's no standardized method, that's why cross-platform frameworks like Flutter exist. Unfortunately, if it's not implemented already there's nothing you can do to get around implementing it on all platforms yourself. If you do decide to do this, it will likely be way easier to do it through normal platform channels instead of ffi. – Christopher Moore Apr 18 '22 at 14:48
  • There's a new package for this: https://pub.dev/packages/pasteboard – Marwin Lebensky Aug 04 '22 at 09:51

1 Answers1

0

Windows workaround

required plugin: process_run: ^0.12.3+2 (view on pub.dev)

final res = await Shell().run('''
powershell -c "(Get-Clipboard -Format Image).Save('C:/temp/temporary.png')"
powershell -c "[convert]::ToBase64String((get-content 'C:/temp/temporary.png' -encoding Byte))"
''');
print(res[1].stdout.trim());

res[1].stdout contains the image in base64 format.

I really do not like this solution, but it works at least for windows.

Marwin Lebensky
  • 270
  • 1
  • 2
  • 16