Hello there, this is a demonstration of how to use alternative ways to access native APIs in Flutter (or any dart application for that matter, including CLIs).
Screen.Recording.2023-06-01.at.23.43.33.mov
This repo includes:
- At first level, a Flutter Apllication that contains only one screen that can have a text from its textfield copied to the clipboard with HTML formatting (bold).
- Inside the
packages
folder, there are four packages:pasteboard
: A dart-only package that handles the clipboard access. It is works like a federated plugin: it means it can be called from the dart applciation and itself will figure out which platform implementation to use.pasteboard_macos
: A macOS implementation of thepasteboard
package. It uses thedart:ffi
package to access the native APIs, namely the homonimousPasteboard
(NSPasteboard
) API. The binding is imported form theappkit_bindings
package (also in this repo).pasteboard_windows
: A Windows implementation of thepasteboard
package. It uses the awesomewin32
package to access the native windows APIs.appkit_bindings
: A dart-only package that contains the bindings for the macOS native APIs. It was generated by theffigen
package using a system header as entry point for the binding generated.
See that the native implemmentations are in their own packages, and the dart-only package is totally independent of flutter. So anyone could use this on dart CLIs too. Native implemmentations are extensible to use the complete fueature set of its native counterparts, for example, the macOS implementation can potentially handle images and files, as well as the Windows one.