/dart_only_plugin_demo

A dart-only clipboard plug-in that just works (demo)

Primary LanguageDart

Dart only "plugins" demonstration

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

What this repo includes

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 the pasteboard package. It uses the dart:ffi package to access the native APIs, namely the homonimous Pasteboard (NSPasteboard) API. The binding is imported form the appkit_bindings package (also in this repo).
    • pasteboard_windows: A Windows implementation of the pasteboard package. It uses the awesome win32 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 the ffigen 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.