Load pre-compiled dart code at runtime using a shared library

184 Views Asked by At

Let's assume I have the following project structure:

interfaces/
  A.dart, B.dart, etc
app/
  main.dart, etc
addon1/
  Aimpl.dart, Bimpl.dart, etc
addon2/ etc

The code being executed lies in app/, with some features using the functionalities defined in the interfaces located under interfaces/. However, the actual implementation of those interfaces lie in various addonX/ folders, whose code ONLY accesses code in the interfaces/ folder. The name of that folder might be a bit misleading, really it should be shared/, as my addon/ code is also allowed to instantiate classes from there and so on.

When I compile my app this way, everything works fine - after all, it's all the same project.

However, I would now like to essentially "outsource" the whole code in the addon folders, initially only compiling my interfaces/ and app/ code, and then loading various implementations (which can therefore be chosen by the user) at runtime.

In essence, I would like to have a plugin system where each plugin has access to all interfaces and functionalities in a shared folder (the shared folder would, in essence, be the SDK of my project), similar to how it can be done in Java with the usage of pre-compiled jar files. About a decade ago I saw one implementation of this system that I quite liked in the Bukkit project.

Is there a simple way to achieve this in dart? I've seen some talk about plugins in dart on stackoverflow already, but it took a much different form, with plugins "communicating" with the main app via messages, which is, imo, incredibly cumbersome.

0

There are 0 best solutions below