registerReceiver function

Stream<ActionIntent> registerReceiver([
  1. List<String>? actions
])

注册广播接收器


StreamSubscription receiver;

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

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

}

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

Implementation

Stream<ActionIntent> registerReceiver([List<String>? actions]) =>
    _controller.stream
        .where((intent) => actions?.contains(intent.action) ?? true);