Difference between onEvent.Listen() and addEventListener

Issue

I’m relatively new to Dart. I’m mainly building very small Dart/HTML applications on Dartpad, but I would like to know:

what are the main differences between element.addEventListener(type, callback); and element.onEvent.listen(callback);, and where will those differences provide me an advantage, in what way, and in what situations?

Thanks!

Solution

Seems like no one is going to give an answer, so I’ll share a bit of my knowledge for anyone else who may have spotted this.

The only differences I can see are that addEventListener can add a listener dynamically to different types of events as you can pass a string into it –

var str = "click";
element.addEventListener(str, (_) {
    print(1);
});

and possibly Streams may have unique methods that allow you to customize your event listener with element.onEvent.listen more.

Answered By – gosoccerboy5

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

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