I have a flutter application running on the Dart programming language. I have published an npm package that I want to use in my flutter application. Is there any way I can use the existing npm package in dart or somehow automatically convert npm package to dart package?
To create a package. json file, run npm init in the root folder of your project. After running this command, it asks you for some data about your project, you can choose to answer them or just press enter to set the data values to default. You can also execute the command npm init -y to create the package.
Dart and Javascript are different programming languages. While it might be possible to transpile you lib from js to dart, it is not easily doable, nor maintainable, and most likely not generalisable.
Unless you are comfortable with both languages and their limitations, you should not try to convert an NPM package to some Dart code unless you don't have any other choice.
I would advise you to rewrite the NPM package in Dart instead.
REMARK : this answer is based on the hypothesis that you don't want to integrate JS code in a webview but actually use the code inside the Dart VM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With