How to call a Dart function from Javascript in Flutter Web?

Viewed 222

How can I call a Dart function from Javascript in Flutter Web? I have tried so many solutions available here but none of them worked. I am trying to do something like this.

  @override
  void initState() {
    String foo() {
      return "bar!";
    }
    js.context['foo'] = js.allowInterop(foo);
    super.initState();
  }

and in JS

 <script>
   console.log("foo() = " + foo());
</script>

But it's always showing me foo() is not defined. Please don't mind I am not good in web.

0 Answers
Related