plug 1.0.1 copy "plug: ^1.0.1" to clipboard
plug: ^1.0.1 copied to clipboard

A Dart/Flutter package to deal with async communication between 2 instances or methods

LogoType

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.

Buy Me A Coffee
1
likes
150
points
55
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart/Flutter package to deal with async communication between 2 instances or methods

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on plug