📌  相关文章
📜  如何在 dart 中向对象添加侦听器 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:28.398000             🧑  作者: Mango

代码示例1
import 'dart:async';

class BaseModel {
  Map objects;
  StreamController fetchDoneController = new StreamController.broadcast();

  // define constructor here

  fetch() {
    // fetch json from server and then load it to objects
    // emits an event here
    fetchDoneController.add("all done"); // send an arbitrary event
  }

  Stream get fetchDone => fetchDoneController.stream;

}


// over in youre app file

main() {
  var model = new BaseModel();
  model.fetchDone.listen((_) => doCoolStuff(model));
}