Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

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));
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #listner #object #dart
ADD COMMENT
Topic
Name
3+8 =