Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/renancaraujo/dart_only_plugin_demo

A dart-only clipboard plug-in that just works (demo)
https://github.com/renancaraujo/dart_only_plugin_demo

Last synced: 18 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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).

https://github.com/renancaraujo/dart_only_plugin_demo/assets/6718144/3abfab4b-ece6-43e8-bf34-17544c1e0c37

### 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.