Solved: Is it possible to run a js or python script from a .js or .py file when a button in Flutter is pressed? (Not Flutter Web)

Question

Asked by Tin P on December 21, 2021 (source).

I want to make a flutter app that, when a button is pressed, it runs a python or a js script that I made and is saved in a .js or a .py file. Essentially, I want to run a .js or a .py file when a button in Flutter is pressed. Is that possible? And if yes, how can it be done? I am making a desktop application that has to work offline.

Answer

Question answered by Expurple (source).

Yes, this is possible, but it requires Python and JS interpreters to be installed on the device. A way to ensure this is to ship them together with your app, although this will take a lot of extra space. From your app, you just launch the interpreter as a subprocess, for example python3 your_script.py

If your script is hardcoded and not changed later by the app, you can also turn it into a standalone executable, using a tool such as py2exe. But this is basically the same thing, the interpreter just ends up included in your script.

Video Answers on YouTube

DART FLUTTER JAVASCRIPT PYTHON
SHARE: