简体   繁体   中英

How to use a JS library and a JS function in a Flutter mobile app?

I want to use a JavaScript library in my mobile Flutter project. Here is the link for this library on github.

Library

How can I use this library and a function(aboutnumber()) from it in my project? How can I import this library to a project and how to access its function?

You can use https://pub.dev/packages/flutter_js package. It allows to evaluate pure javascript code inside mobile and desktop flutter apps. By pure, I mean the package is not a browser engine, so no web API, localstorage or another browser api are available. But you can bundle some javascript code containing javascripts libraries like moment, ajv and maybe the one you related in your question if it relies only in javascript. The flutter_js injects into the javascript engine, things like console.log, xhr and fetch. But it is all. There is a send message channel which you could use to inject objects into the engine which you could provide objects which will be implemented and dart, but will be shared into the javascript global space.

In Flutter web, the javascript integration is possible using the package:js, mentioned in another answer.

Disclaimer: I'm the author of the flutter_js package

This is not possible on any platform other than the web, as described in the JS interop documentation .

On the Web, package:js can be used.

As mentioned in this other similar question , there's also webview_flutter , which embeds a whole web view onto Flutter, and that's an official Flutter package as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM