【发布时间】:2019-04-14 04:50:42
【问题描述】:
考虑这段代码(不要介意listen这个没用的方法,它只是为了展示用例):
class Bloc {
final BehaviorSubject notifPrompt =
BehaviorSubject<NotifPromptModel>()..add(NotifPromptModel(answered: false));
void listen() {
notifPrompt.stream.listen(
(data) => print(data.answered)
);
}
void dispose() {
notifPrompt.close();
}
}
class NotifPromptModel {
final bool answered;
NotifPromptModel({this.answered});
}
现在我知道这会起作用,但是在这种情况下,有没有办法获得generic type、NotifPromptModel,我将其传递给BehaviorSubject(StreamController,每一次发送最后一个event带有data 参数的新listen)?当我将包含model 信息的object 作为fields 传递给BehaviorSubject 时,这将允许我获得方便的代码建议,就像在这种情况下一样。
【问题讨论】:
标签: stream dart flutter rxdart