简体   繁体   English

Flutter Bloc package,当本机代码从 ZBB14127678960FAE97D873 调用方法时产生 state

[英]Flutter Bloc package, yield state when native code invoke a method from dart

In my bloc I have 2 streams.在我的集团中,我有 2 个流。 One is the mapEventToState where I can yield states, and I created a second one which is called from a function which is called by native code.一个是mapEventToState ,我可以在其中产生状态,我创建了第二个从本地代码调用的 function 调用。

The call:来电:

checkStatus(_internalState).listen((data){});

The Stream: Stream:

Stream<VpnConnectionState> checkStatus(_internalState) async * {
switch (_internalState) {
  case state.down:
    yield down();
    break;
  case state.up:
    yield up();
    break;
}
_previousState = _internalState;
}

The problem is when I yield something in the checkSatus stream, is not arriving in my BlocBuilder.问题是当我在checkSatus stream 中yield一些东西时,没有到达我的 BlocBuilder。 If is called from the stream mapEventToState is working.如果从 stream 调用mapEventToState正在工作。

These are completely different streams.这些是完全不同的流。 Your BlocBuilder is listening to your mapEventToState stream not for your checkStatus .您的BlocBuilder正在收听您的mapEventToState stream 而不是您的checkStatus Dispatch (or add in the latest version) event from your checkStatus stream to your block and then yield new state in mapEventToState when responding to those events.将 checkStatus stream 中的事件Dispatch (或add到最新版本)到您的块,然后在响应这些事件时在mapEventToState中生成新的 state。

Or even get rid of your checkStatus stream for simplicity like here:或者为了简单起见,甚至摆脱您的 checkStatus stream ,如下所示:

void checkStatus(_internalState) {
switch (_internalState) {
  case state.down:
     dispatch(DownEvent());
    break;
  case state.up:
    dispatch(UpEvent());
    break;
}
_previousState = _internalState;
}

void mapEventToSteam(Event event) {
    if(event is DownEvent) {
     yield DownState()
   }
    if(event is UpEvent) {
     yield UpState()
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM