0

考虑这段代码(不要介意无用的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 typeNotifPromptModel在这种情况下使用参数传递给BehaviorSubject(在每个新的StreamController最后发送)?当我传递一个包含关于 的信息时,这将使我有方便的代码建议,就像在这种情况下一样。eventlistendataobjectmodelfieldsBehaviorSubject

4

1 回答 1

0

应该多花几分钟思考。问题是我用 实例化了BehaviorSubject objecttype但没有declarevariable它实例化。

于 2018-11-11T04:09:39.557 回答