How to prevent on.submit event from changing / reloading a page?

In Javascript , when I provide a function onSubmitand I return 'false' from the function, this prevents the page from changing / reloading.

However, in Dart, the function onSubmit.listen(...)does not accept a return type.

How to stop sending from sending form data and changing / reloading the page?

+5
source share
1 answer

In the callback on.submit.add(...)you will get Eventas an argument. The object Eventprovides a method preventDefault()to prevent or reverse the default action.

It can be used as follows:

querySelector('#myForm').onSubmit.listen((Event e) {
  // ... your code here
  e.preventDefault();
});
+6
source

All Articles