action_broadcast 2.1.1 copy "action_broadcast: ^2.1.1" to clipboard
action_broadcast: ^2.1.1 copied to clipboard

outdated

一个简单的全局广播系统,类似于Android的本地广播

action_broadcast #

pub package

一个简单的全局广播系统,类似于Android的本地广播

Usage #

Listen #

  • 传统使用方式

 const actionUserLogin = 'actionUserLogin';
 const actionUserInfoChange = 'actionUserInfoChange';
 const actionLogout = 'actionLogout';

 StreamSubscription receiver;

 @override
 void initState() {
    super.initState();

    receiver = registerReceiver(['actionUserLogin','actionUserInfoChange','actionLogout']).listen((intent){
            switch(intent.action){
                case 'actionUserLogin': accountId = intent.data;
                             break;
                case 'actionUserInfoChang': nickname = intent['nickname'];
                             break;
                case 'actionLogout': Navigator.pop(context);
                             break;
            }
    });
 }

 @override
 void dispose(){
   receiver.cancel();
   super.dispose();
 }

  • State中混入自动化管理StreamSubscriptionAutoCancelStreamMixin以简化工作

class _ExampleState extends State<Example> with AutoCancelStreamMixin{

  @override
  Iterable<StreamSubscription> get registerSubscriptions sync* {
    yield registerReceiver([actionExample]).listen((intent) {
        setState(() {
          // do something
        });
      },
    );
  }

}

Notify #

sendBroadcast(actionUserLogin,extras:{'accountId':'adc'});

sendBroadcast(actionUserInfoChang,data:'nickname');

4
likes
0
pub points
85%
popularity

Publisher

unverified uploader

一个简单的全局广播系统,类似于Android的本地广播

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on action_broadcast