Answers for "how to add a listner to a object in dart"

0

how to add a listner to a object in dart

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));
}
Posted by: Guest on July-20-2021

Code answers related to "how to add a listner to a object in dart"

Browse Popular Code Answers by Language