JakesMD
JakesMD

Reputation: 2196

How to use NodeJS package in Flutter web app

I have a Flutter web app that needs to be able to create a virtual midi device. For this, the only option seems to be to use the easymidi NodeJS package. What is the best way of connecting a NodeJS script to a flutter app?

Upvotes: 1

Views: 2110

Answers (1)

Dominik Šimoník
Dominik Šimoník

Reputation: 1602

You can connect to javascript from flutter web. Best way is to use dart:js library.

Add your custom js file to web directory a make sure that it's loaded

<head>
    <script src="your.js" defer></script>
</head>

For example

function info(text) {
    alert(text)
}

Calling from dart:

import 'dart:js' as js;

js.context.callMethod('info', ['Hello!']);

Upvotes: 2

Related Questions