How to prevent click event propagation

Issue

When using a material button inside a container and you click on the material button, it triggers the material button event handler, but then it propagates up to the container. What is the recommended way to stop the event from propagating beyond the material button?

Solution

event.stopPropagation() will stop it propagating.

event.preventDefault() stops any native action the event would have.

https://api.dart.dev/stable/2.8.3/dart-html/Event-class.html

Answered By – Ted Sander

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

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