plugins 1.0.3 copy "plugins: ^1.0.3" to clipboard
plugins: ^1.0.3 copied to clipboard

A simple plugin loading system

Plugins #

A simple plugin loading system.

A plugin system allows you to extend functionality of your system. Other developers can hook into your APIs through the plugins library and interact with each other at ease.

Example #

Initializing the loader is very simple

import 'package:plugins/loader.dart';

void main() {
  PluginManager pm = new PluginManager();
  Directory path = new Directory("plugins");
  pm.loadAll(path).then((_) {
    pm.listenAll((name, data) {
      print("Received data from plugin '$name': ${data[0]}");
      pm.killAll();
    });
    Map m = new Map();
    m[0] = "Hello from loader!";
    pm.sendAll(m);
  });
}
copied to clipboard

The plugins folder will look something like:

.
+-- test
|   +-- main.dart
|   +-- pubspec.yaml
|   +-- lib/
|   +-- packages/
copied to clipboard

Your lib folder can contain more code as needed for functionality. Dependencies will work the same as usual for plugins. The pubspec.yaml file must contain, at a minimum, the name.

Creating a plugin for a loader is just as simple as creating a loader.

import 'package:plugins/plugin.dart';
import 'dart:isolate';

void main(List<String> args, SendPort port) {
  Receiver rec = new Receiver(port);
  rec.listen((Map<dynamic, dynamic> data) {
    print("Received data in plugin: ${data[0]}");

    Map info = new Map();
    info[0] = "Hello from plugin!";
    rec.send(info);
  });
}
copied to clipboard

The examples can give you more insight for more powerful APIs. Visit the documentation for more information about the APIs. Open an issue for any problems or suggestions.

1
likes
35
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.26 - 2025.04.10

A simple plugin loading system

Repository (GitHub)

License

MIT (license)

Dependencies

path, yaml

More

Packages that depend on plugins