Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

samrg472/plugins.dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
|   |- bin
|   |  +-- 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.

About

A simple plugin loading system

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages