Home > OS >  How to call a JS function from Flutter Web?
How to call a JS function from Flutter Web?

Time:03-22

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();
}

CodePudding user response:

See dart:js library

import 'dart:js';

main() => context.callMethod('alert', ['Hello from Dart!']);
  • Related