Search code examples
node.jsflutterdartflutter-webweb-midi

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?


Solution

  • 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!']);