plugins 1.0.3 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);
});
}
The plugins folder will look something like:
.
+-- test
| +-- main.dart
| +-- pubspec.yaml
| +-- lib/
| +-- packages/
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);
});
}
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.