Consider this code (don't mind the useless listen
method, it's just to show the use case):
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});
}
Now I know that this will work, but is there a way to get the generic type
, NotifPromptModel
in this case, that I pass to the BehaviorSubject
(StreamController
that sends last event
on every new listen
) with the data
parameter? This would allow me to have convenient code suggestions when I'm passing an object
containing the model
information as fields
to the BehaviorSubject
, like in this case.
Should have spent some minutes more thinking. The problem was that I instantiated the
BehaviorSubject
object
with thetype
, but didn'tdeclare
thevariable
with it.