plug 1.0.1 plug: ^1.0.1 copied to clipboard
A Dart/Flutter package to deal with async communication between 2 instances or methods
A Dart/Flutter package to deal with async communication between 2 instances or methods.
It works like a cable connecting two class instances.
Each Plug can only have one corresponding connection, and it works by transmitting and receiving asynchronous signals and values.
Table of Contents #
Plug with signal #
void main(){
FirstClass firstClassInstance = FirstClass();
SecondClass secondClassInstance = SecondClass();
firstClassInstance.onSignal.then(secondClassInstance.handleSignal);
firstClassInstance.someMethod();
}
class FirstClass{
Plug onSignal = Plug();
someMethod(){
...some work
onSignal();
}
}
class SecondClass{
handleSignal(){
print('signal received');
}
}
Plug with data #
void main(){
FirstClass firstClassInstance = FirstClass();
SecondClass secondClassInstance = SecondClass();
firstClassInstance.onData.take(secondClassInstance.handleData);
firstClassInstance.someMethod();
}
class FirstClass{
Plug<int> onData = Plug();
someMethod(){
...some work
onData.send(10);
}
}
class SecondClass{
handleData(int value){
print('value received $value');
}
}
#
Contribute #
If you have some improvement or correction to make, please feel free to open an issue or pull request on the github project. All feedback are very welcome.