Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listening for event in Dart via JQuery “on” with dart:js

I use dart call bootstrap modal window,and I want register a callback function ,but found the same problem other person mentioned before.

here is jQuery code:

$('#myModal').on('hidden.bs.modal',function (e) {....})

How can I write the same code in dart with dart:js, because package:js is deprecated; so I can't use callback function .

Thanks a lot !!!

like image 618
dylb1973 Avatar asked Jan 30 '26 16:01

dylb1973


1 Answers

This should work

import 'dart:js' as js;
...
void someCallback(e) {
  print('callback called, passed: $e');
}
...
js.context.callMethod(r'$', ['#myModal'])
    .callMethod('on', ['hidden.bs.modal', someCallBack]);

or

...
js.context.callMethod(r'$', ['#myModal'])
    .callMethod('on', ['hidden.bs.modal', (e) {
        print('callback called, passed: $e');
}]);
like image 93
Günter Zöchbauer Avatar answered Feb 01 '26 06:02

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!