EventEmitter is deprecated and shouldn't be used


In AngularDart 3.0.0 EventEmitter is deprecated. So, how to send event from child component to parent?

Before update it is looks like:

  selector: 'my-test',
  templateUrl: 'test.component.html'
class TestComponent {
  String name = '';

  EventEmitter<String> onNameChange = new EventEmitter<String>();

onNameChange.emit('New Name');

Now I need use Stream and StreamController. Can someone give an example?


Just use a normal StreamController

final _onNameChangeController = new StreamController<String>.broadcast();
Stream<String> get onNameChange => _onNameChangeController.stream;

.broadcast is optional. It is required to allow multiple subscribers.

See also https://www.dartlang.org/articles/libraries/broadcast-streams

Answered By – Günter Zöchbauer

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *