Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 如何访问合并流的上一个值?_Dart_Flutter_Reactive Programming - Fatal编程技术网

Dart 如何访问合并流的上一个值?

Dart 如何访问合并流的上一个值?,dart,flutter,reactive-programming,Dart,Flutter,Reactive Programming,我已经为此挣扎了几个小时,似乎找不到解决办法。我将感谢任何帮助 我正在构建一个颤振应用程序,试图遵循集团模式。 我有一个小部件,有两个文本字段:国家代码和电话号码。 我定义了一个具有两个接收器(每个字段一个)和一个具有状态的流的Bloc。流状态是两个接收器的合并,例如: factory AuthenticationBloc(AuthenticationRepository authRepository) { final onPhoneChanged = PublishSubject<

我已经为此挣扎了几个小时,似乎找不到解决办法。我将感谢任何帮助

我正在构建一个颤振应用程序,试图遵循集团模式。 我有一个小部件,有两个文本字段:国家代码和电话号码。 我定义了一个具有两个接收器(每个字段一个)和一个具有状态的流的Bloc。流状态是两个接收器的合并,例如:

factory AuthenticationBloc(AuthenticationRepository authRepository) {
    final onPhoneChanged = PublishSubject<String>();
    final onCountryChanged = PublishSubject<String>();

    //oldState would be the last entry in the stream state.
    final stateChangeFromThePhone = onPhoneChanged.map((newPhone)=>oldState.copyWith(phone:newPhone));
    final stateChangeFromtheCountry = onCountryChanged.map((newCountry)=>oldState.copyWith(country:newCountry));
    final state = Observable.merge[stateChangeFromThePhone, stateChangeFromtheCountry];
}
FactoryAuthenticationBloc(AuthenticationRepository authRepository){
最终onPhoneChanged=PublishSubject();
最终onCountryChanged=PublishSubject();
//oldState将是流状态中的最后一个条目。
final stateChangeFromThePhone=onPhoneChanged.map((newPhone)=>oldState.copyWith(phone:newPhone));
final state changefromthecountry=onCountryChanged.map((newCountry)=>oldState.copyWith(country:newCountry));
最终状态=可观察。合并[来自电话的状态更改,来自国家/地区的状态更改];
}
这是一段伪代码,但思想是存在的。我的问题是如何从oldState代码中表示的状态流中访问最新事件

我可以定义一个变量,在状态流中的每个新事件上存储该值,但看起来很难看…:(


有什么建议吗?

你不能。如果你想,你必须有目的地公开它。谢谢你的快速回复。你对如何实现这种模式有什么建议吗。它似乎不像一个疯狂的用例……大多数示例都有一个简单的输入。不是几个输入的组合来计算输出状态:(考虑到您使用的是rx,您可以使用
缓冲区
操作符。例如。并使一个可观测值同时发出当前值+上一个值。谢谢。除非我遗漏了什么,否则我不确定这是否可行,因为我需要的不是以前版本的电话或国家代码。而是以前版本的状态“When”手机或国家/地区发生变化。这让我别无选择,只能通过将其保存在变量中来公开以前的状态。奇怪的是,没有优雅的解决方案来解决此问题……我无法得到您想要的。如果
merge
不适合您的情况,可能
combinelatetest
或任何其他融合操作符都可以。