[SOLVED] How to call a JS function from Flutter Web?

Issue

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

Solution

See dart:js library

import 'dart:js';

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

Answered By – Brandon Pillay

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

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