考虑这段代码(不要介意无用的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
listen
data
object
model
fields
BehaviorSubject