Can you run JavaScript in Flutter?

  Рет қаралды 8,479

Andrei Lupsa

Andrei Lupsa

Күн бұрын

I didn't find a good Dart library able to parse math expressions, so I jumped the fence and borrowed one from JavaScript. Is this good or bad?
Why am I switching to Flutter in 2024
• Why am I switching to ...
Download my app here:
www.allinonecalculator.com
00:00 - Introduction
00:25 - Why I need it
02:37 - How I did it
05:50 - What are the caveats
06:23 - Conclusion
Thank you for watching!

Пікірлер: 79
@LukePighetti
@LukePighetti 2 ай бұрын
not stupid, very smart and pragmatic. you have a high quality math engine with a few lines of code that will last forever and continue improving and evolving until the end of time
@andreiIupsa
@andreiIupsa 2 ай бұрын
Building on this. Imagine having snippets of business logic that you can use inside your app and update instantly through a web service. Can't really think of a valid use case but it's possible.. 😁
@HazhanJalal
@HazhanJalal 2 ай бұрын
​@@andreiIupsa Building the app (AAB/APK) with shorebird can help you do that with pure Flutter as-well (the push updates directly part). Super easy too. You do your edits normally, change any codes you have, and with a single line from the terminal the app is updated on user's device next time they open it without requiring them to install any updates through any store. But it does have some limitations. For example Adding new resources Always requires sending new App package (AAB/APK), can't send those through patches. And also costs abit for large users-base apps. For smaller userbase (maybe a company's private own app) super useful and won't cost a dime.
@ISKLEMMI
@ISKLEMMI 2 ай бұрын
You had a problem and you solved it in a manner that allows you to keep making progress. I count this as a victory. I'm fairly new to Flutter and had no idea you could do this. Thanks for sharing!
@wraith3108
@wraith3108 2 ай бұрын
Man this is how you are supposed to tell about your journey of the framework. Every tech has their ups and downs and how you are supposed to tackle the downs in a tech is what is needed. Rather than just complaining about it. Seriously, I loved your video and your way of delivery.
@andreiIupsa
@andreiIupsa 2 ай бұрын
Thank you!
@TahiruAgbanwa
@TahiruAgbanwa 2 ай бұрын
This is really smart to think about. I have never used a JS package in flutter. This unlocks a lot of possibilities
@andreiIupsa
@andreiIupsa 2 ай бұрын
Think about having snippets of code that you can change on the fly in your app. Can't think of a specific use case, but it's possible!
@BooleanDev
@BooleanDev 2 ай бұрын
@@andreiIupsasome apps do that for website parsers so that they can update it quickly if it breaks
@jointtask4047
@jointtask4047 2 ай бұрын
I recommend you do the evaluation on a diff tread using the compute or isolate function in dart, that will increase performance and reduce jank when evaluating large expressions
@listendream2792
@listendream2792 2 ай бұрын
Thank you for your sharing, love your videos and inspire me alot. Keep up the good work!!🧡🧡
@AbdulHaseeb-sy7uo
@AbdulHaseeb-sy7uo 2 ай бұрын
You made my day, letting me know what is possible with flutter! thank you so much Andrei . I have subbed your channel!
@theskyblockman
@theskyblockman 2 ай бұрын
This is good for your app but shows a massive problem for the Dart ecosystem (and many others): If people look over the fence too much, no development in Dart would be made and we would all go to JS. I am also not a fan of creating another entire runtime when the app starts. I am mainly against just using other languages like that because I ported 2 giant decompilers from Python to Dart and I want other people to suffer with me. This looks like a fun project for my next vacation though!
@rodrodrigues1729
@rodrodrigues1729 2 ай бұрын
being creative is essential for programming, nicely done. the end of the video is really cool as well.
@gofullstack
@gofullstack 2 ай бұрын
To initialise this ones on start-up I'll prefer to do this instead class Math { static JavascriptRuntime? _instance; static void initialize() async => _instance ??= await _initialize(); static Future _initialize() async { final library = await rootBundle.loadString("res/libraries/math.js"); final runtime = getJavascriptRuntime(); await runtime.evaluateAsync(library); return runtime; } static Future evaluate(String text) async { final result = await _instance?.evaluateAsync("math.evaluate('$text')"); return result?.rawResult; } } This means you don't need to call evaluate for any reason again unless required because "Math.evaluate("1+1");" becomes "Math.initialize();" and you’ll have your JS Runtime initialised before your user needs it.
@mycloudvip
@mycloudvip 2 ай бұрын
awesome work. for me getting the job done is worth more than the approach you take. Kudos!
@alexamatobi3769
@alexamatobi3769 2 ай бұрын
Amazing... I'll be trying this out
@felix_arg984
@felix_arg984 2 ай бұрын
This is quite pragmatic and smart🙌 Another language that you could try out would possible be rust, there is a crate called meval which should do the same and with the flutter rust bridge you should be able to easily run it on all platforms quite performantly :) But if it works in JS, that‘s the important thing that matters.
@harishprasadrajeurs2771
@harishprasadrajeurs2771 17 күн бұрын
very informative
@thelastbit8154
@thelastbit8154 2 ай бұрын
Thanks, I have some ideas for this 👌
@programingtales7514
@programingtales7514 Ай бұрын
Thats really cool
@memoriasIT
@memoriasIT 2 ай бұрын
I don't know how to feel about this, but cool stuff :D
@trungbui7518
@trungbui7518 Ай бұрын
Can you show me how to parse json with worker in flutter web?
@matthieupernelle8074
@matthieupernelle8074 2 ай бұрын
Can you translate a Js or Java library to dart with ChatGPT ?
@gauravjoshi747
@gauravjoshi747 2 ай бұрын
can you open source it so that we can learn and contribute to it
@alaaabdalqader9718
@alaaabdalqader9718 26 күн бұрын
can u make a video how to extract images from pdf file in flutter ?
@YayoArellano
@YayoArellano 2 ай бұрын
This is a great video and a very smart approach to solving your problem. I would like to know how you record and edit your videos. They look great.
@andreiIupsa
@andreiIupsa 2 ай бұрын
Hmm.. I'm a geek when it comes to cameras and photography so this won't be a short answer. First, lighting is important. I have a single Elgato Key Light set to 100% 5500k right in front of me. I use a Sony A7IV camera, a 16-35 F2.8 GM lens with a Nisi True Color 1-5 stops variable ND. I film in 4k 30p 4:2:2 10-bit S-Log XAVC-S 1/60. Camera WB is set to manual 5500k. I overexpose the log footage with 1 stop and I don't use in camera sharpening. I use the Phantom Luts Eastman lut and I add some sharpening in post. For audio I switched from the Shure SM7B to the Sennheiser MKE 400. 😁
@YayoArellano
@YayoArellano 2 ай бұрын
@@andreiIupsa lol. I still have many things to learn. Thanks for ur answer
@michaelchiz8055
@michaelchiz8055 2 ай бұрын
Nice
@thecigaroman
@thecigaroman 2 ай бұрын
If you had a working java library I think you could try to run that via Dart FFI and JNIGen. At least it's worth prototyping I think.
@mikopiko
@mikopiko Ай бұрын
5:11 any specific reason why you didn't just stick to a function and had to wrap it in a class?
@ebitdaddyca3676
@ebitdaddyca3676 2 ай бұрын
Nice format, nice editing, nice app
@andreiIupsa
@andreiIupsa 2 ай бұрын
Thank you 😃
@leoingson
@leoingson 2 ай бұрын
+1, stole my comment :)
@cristiancosneanu
@cristiancosneanu 2 ай бұрын
This is quite a nice solution. I never used the flutter_js lib... I think it is hilarious that it doesn't work on web. Code wise: You could separate the initial loading and the evaluation, and put the inital loading in a Isolate, might improve the loading time. LMK if you need an example. Cheers.
@andreiIupsa
@andreiIupsa 2 ай бұрын
I tried to run everything inside Isolate.run() but for some reason the JS execution fails there. Will look into it when I have the time.
@cristiancosneanu
@cristiancosneanu 2 ай бұрын
@@andreiIupsa Interesting... Only the loading? or the evaluation also?
@BinaryBridgeHQ
@BinaryBridgeHQ 2 ай бұрын
I like the solution, I love flutter, I develop applications using flutter on daily basis and I can't go back, No matter what I try, I just want to stick to flutter.
@nonefvnfvnjnjnjevjenjvonej3384
@nonefvnfvnjnjnjevjenjvonej3384 2 ай бұрын
would react native be a better choice here? for easier js interop?
@TahiruAgbanwa
@TahiruAgbanwa 2 ай бұрын
JS interop is only needed for flutter web and not mobile or desktop. But to answer ur question, react native uses js so why do you need a js interop package. just install the package an use it. There is no better choice here, if it works it works except in RN it would have been more straight forward.
@user-cz5cy8ud8m
@user-cz5cy8ud8m 2 ай бұрын
Hi! could I ask you why you did choose Flutter instead of KMP though you already were using Android native? :)
@mibi2007
@mibi2007 2 ай бұрын
because Flutter views more than KMP I think 😁
@TheAbhidugar
@TheAbhidugar 2 ай бұрын
from where did you learn to use riverpod?
@andreiIupsa
@andreiIupsa 2 ай бұрын
The getting started documentation they provide is all you need.
@prabalverma334
@prabalverma334 Ай бұрын
good
@momshaddinury
@momshaddinury 2 ай бұрын
This is amazing, genius. By any chance is it possible to render math equation like calculus natively without using webview?
@andreiIupsa
@andreiIupsa 2 ай бұрын
The runtime runs natively and doesn't use a webview, as far as I know.
@momshaddinury
@momshaddinury 2 ай бұрын
@@andreiIupsa Do you need to render complex LaTeX formatted equations?
@Snggle
@Snggle 2 ай бұрын
Nice, can't wait until you try large TS packages that are sdks lmao.
@scratchindonuts7903
@scratchindonuts7903 2 ай бұрын
Messi teaching Flutter now? Nice.
@flutter-fm1kl
@flutter-fm1kl 2 ай бұрын
Bro, please use a dark theme because the eye is important.
@andreiIupsa
@andreiIupsa 2 ай бұрын
Can't stand it, unfortunately..
@gaxkiller
@gaxkiller 2 ай бұрын
@@andreiIupsa I can't stand bright theme but I understand some people prefer it, and since it SUPER easy to make dark + bright theme and switch between theme in flutter, I do this all the time :) Since you use riverpod, just define all your theme data in providers. How I do: - themeProvider -> returns a theme data, then other providers returning part of the theme. For the colorScheme: final colorSchemeProvider = Provider((ref) { final brightness = ref.watch(brightnessProvider); final colorSchemeSeed = ref.watch(colorSchemeSeedProvider); return ColorScheme.fromSeed( seedColor: colorSchemeSeed, primary: colorSchemeSeed, brightness: brightness, ).copyWith( surfaceTint: Colors.transparent, ); }); The brightness provider is super simple: final brightnessProvider = StateProvider((ref) => Brightness.light); Then from anywhere in the app, you can use the brightnessProvider to swtich between dark and bright. Of course, you have to use the colorSchemeProvider inside you theme provider to set the colorScheme for this to work
@asandax6
@asandax6 2 ай бұрын
​@@andreiIupsa Use it only when recording.
@mikopiko
@mikopiko Ай бұрын
Does white theme hurt the eyes?
@flutter-fm1kl
@flutter-fm1kl Ай бұрын
@@mikopiko yeah for me
@derismekentz1
@derismekentz1 2 ай бұрын
most underated ending ever
@andreiIupsa
@andreiIupsa 2 ай бұрын
Chickens! 😁
@ahmadjz8144
@ahmadjz8144 2 ай бұрын
Since you're already using FFI for running other languages in Flutter, why did you choose JS? why not Python for example
@s.bamahfoodh
@s.bamahfoodh 2 ай бұрын
Wait, do u mean that we can use libraries from different languages in flutter and it will just work???
@saiphaneeshk.h.5482
@saiphaneeshk.h.5482 2 ай бұрын
​@@s.bamahfoodhwondering the same.
@ahmadjz8144
@ahmadjz8144 2 ай бұрын
Yeah you can say that, it's called FFI (Foreign Function Interface), it supports multiple languages even C
@ShivamJha00
@ShivamJha00 2 ай бұрын
Every language that has a C interop will work. I've seen some libraries using rust as well
@KlawaJunior
@KlawaJunior 2 ай бұрын
Codict app uses this library
@ransomecode
@ransomecode 2 ай бұрын
kids are going to run xss on your app bro if you put the input directly into evaluate()
@andreiIupsa
@andreiIupsa 2 ай бұрын
Good point! Gotta do some sanitization first. Edit: On second tought.. can they?
@AshishBeck
@AshishBeck 2 ай бұрын
​@@andreiIupsa you're wrapping your evaluation inside the hard-coded "math.evaluate(...)" so I think you're good to go. Doesn't matter now if you let the user input whatever shenanigans they want to as they are restricted by the function.
@user-lj4lo7cx7m
@user-lj4lo7cx7m 2 ай бұрын
​@AshishBeck what about );console.log(1
@AshishBeck
@AshishBeck 2 ай бұрын
@@user-lj4lo7cx7m how will you get outside of the enclosing paranthesis (...) but?
@AshishBeck
@AshishBeck 2 ай бұрын
@@user-lj4lo7cx7m you cannot escape the paranthesis around math.evaluate() though, right?
@agoshxyz
@agoshxyz 2 ай бұрын
All you need is React Native
@kevinmore2012
@kevinmore2012 2 ай бұрын
I mean, you could have put those advanced calculations into a backend and only let paid members to access it.
@koteelok2014
@koteelok2014 2 ай бұрын
lazy
How I got my app to 10 MILLION downloads
8:01
Andrei Lupsa
Рет қаралды 10 М.
Why am I switching to Flutter in 2024
7:01
Andrei Lupsa
Рет қаралды 64 М.
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 34 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 52 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 11 МЛН
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 16 МЛН
The Evolution of Web Apps 1992-2024
14:01
Dylan Beattie
Рет қаралды 24 М.
Why use Type and not Interface in TypeScript
14:12
ByteGrad
Рет қаралды 196 М.
5 Must Know Flutter Packages in 2024 🔥
4:36
TDevelopers
Рет қаралды 1,1 М.
KMP vs. Flutter - Who Will Win The Cross-Platform Battle?
16:19
Philipp Lackner
Рет қаралды 37 М.
JavaScript Visualized - Event Loop, Web APIs, (Micro)task Queue
12:35
This UI component library is mind-blowing
8:23
Beyond Fireship
Рет қаралды 626 М.
Should you use Bun, Deno etc. instead of Node.js?
7:28
Maximilian Schwarzmüller
Рет қаралды 14 М.
TOP 6 Mistakes in RxJS code
18:35
Decoded Frontend
Рет қаралды 15 М.
Building a Flutter Calculator: Part 1, The Layout
16:01
Andrei Lupsa
Рет қаралды 1,1 М.
Are we going back to PHP with fullstack JavaScript?
9:57
Maximilian Schwarzmüller
Рет қаралды 132 М.
Battery  low 🔋 🪫
0:10
dednahype
Рет қаралды 12 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,8 МЛН
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Кинг Комп Shorts
Рет қаралды 1,9 МЛН