Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a JS function from Flutter Web?

I have a simple JS function that I want to call from a Flutter web application:

<script>
    function alertMessage(text) {
          alert(text)
    }
</script>

How can I achieve this?

main.dart:

void onTap(){
    ///This is where I want to call the JS function...  alertMessage();
}
like image 797
Brandon Pillay Avatar asked Jul 13 '26 02:07

Brandon Pillay


1 Answers

See dart:js library

import 'dart:js';

main() => context.callMethod('alert', ['Hello from Dart!']);
like image 124
Brandon Pillay Avatar answered Jul 15 '26 14:07

Brandon Pillay



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!