Can you run JavaScript in Flutter?

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024

Комментарии • 79

  • @LukePighetti
    @LukePighetti 4 месяца назад +56

    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  4 месяца назад +6

      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 4 месяца назад

      ​@@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 4 месяца назад +22

    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 4 месяца назад +15

    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.

  • @sqrlware
    @sqrlware 4 месяца назад +15

    This is really smart to think about. I have never used a JS package in flutter. This unlocks a lot of possibilities

    • @andreiIupsa
      @andreiIupsa  4 месяца назад

      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 4 месяца назад

      @@andreiIupsasome apps do that for website parsers so that they can update it quickly if it breaks

  • @jointtask
    @jointtask 4 месяца назад +10

    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

  • @theskyblockman
    @theskyblockman 4 месяца назад +4

    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!

  • @gofullstack
    @gofullstack 4 месяца назад +5

    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.

  • @ransomecode
    @ransomecode 4 месяца назад +3

    kids are going to run xss on your app bro if you put the input directly into evaluate()

    • @andreiIupsa
      @andreiIupsa  4 месяца назад

      Good point! Gotta do some sanitization first.
      Edit: On second tought.. can they?

    • @AshishBeck
      @AshishBeck 4 месяца назад +1

      ​@@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 4 месяца назад

      ​@AshishBeck what about );console.log(1

    • @AshishBeck
      @AshishBeck 4 месяца назад

      @@user-lj4lo7cx7m how will you get outside of the enclosing paranthesis (...) but?

    • @AshishBeck
      @AshishBeck 4 месяца назад +1

      @@user-lj4lo7cx7m you cannot escape the paranthesis around math.evaluate() though, right?

  • @flutter-fm1kl
    @flutter-fm1kl 4 месяца назад +4

    Bro, please use a dark theme because the eye is important.

    • @andreiIupsa
      @andreiIupsa  4 месяца назад +2

      Can't stand it, unfortunately..

    • @gaxkiller
      @gaxkiller 4 месяца назад

      @@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 4 месяца назад +1

      ​@@andreiIupsa Use it only when recording.

    • @mikopiko
      @mikopiko 4 месяца назад

      Does white theme hurt the eyes?

    • @flutter-fm1kl
      @flutter-fm1kl 4 месяца назад

      @@mikopiko yeah for me

  • @felix_arg984
    @felix_arg984 4 месяца назад +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.

  • @BinaryBridgeHQ
    @BinaryBridgeHQ 4 месяца назад

    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.

  • @바오-c3p
    @바오-c3p 4 месяца назад +1

    Hi! could I ask you why you did choose Flutter instead of KMP though you already were using Android native? :)

    • @mibi2007
      @mibi2007 4 месяца назад

      because Flutter views more than KMP I think 😁

  • @ahmadjz8144
    @ahmadjz8144 4 месяца назад +3

    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 4 месяца назад

      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 4 месяца назад

      ​@@s.bamahfoodhwondering the same.

    • @ahmadjz8144
      @ahmadjz8144 4 месяца назад +1

      Yeah you can say that, it's called FFI (Foreign Function Interface), it supports multiple languages even C

    • @ShivamJha00
      @ShivamJha00 4 месяца назад +1

      Every language that has a C interop will work. I've seen some libraries using rust as well

  • @mycloudvip
    @mycloudvip 4 месяца назад

    awesome work. for me getting the job done is worth more than the approach you take. Kudos!

  • @Snggle
    @Snggle 4 месяца назад

    Nice, can't wait until you try large TS packages that are sdks lmao.

  • @cristiancosneanu
    @cristiancosneanu 4 месяца назад +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  4 месяца назад +1

      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 4 месяца назад

      @@andreiIupsa Interesting... Only the loading? or the evaluation also?

  • @thecigaroman
    @thecigaroman 4 месяца назад +1

    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.

  • @alaaabdalqader9718
    @alaaabdalqader9718 3 месяца назад

    can u make a video how to extract images from pdf file in flutter ?

  • @memoriasIT
    @memoriasIT 4 месяца назад

    I don't know how to feel about this, but cool stuff :D

  • @mikopiko
    @mikopiko 4 месяца назад

    5:11 any specific reason why you didn't just stick to a function and had to wrap it in a class?

  • @trungbui7518
    @trungbui7518 4 месяца назад

    Can you show me how to parse json with worker in flutter web?

  • @scratchindonuts7903
    @scratchindonuts7903 4 месяца назад

    Messi teaching Flutter now? Nice.

  • @alexamatobi3769
    @alexamatobi3769 4 месяца назад +1

    Amazing... I'll be trying this out

  • @KlawaJunior
    @KlawaJunior 4 месяца назад

    Codict app uses this library

  • @YayoArellano
    @YayoArellano 4 месяца назад

    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  4 месяца назад +1

      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 4 месяца назад

      @@andreiIupsa lol. I still have many things to learn. Thanks for ur answer

  • @thelastbit8154
    @thelastbit8154 4 месяца назад +1

    Thanks, I have some ideas for this 👌

  • @harishprasadrajeurs2771
    @harishprasadrajeurs2771 2 месяца назад

    very informative

  • @programingtales7514
    @programingtales7514 4 месяца назад

    Thats really cool

  • @listendream2792
    @listendream2792 4 месяца назад

    Thank you for your sharing, love your videos and inspire me alot. Keep up the good work!!🧡🧡

  • @TheAbhidugar
    @TheAbhidugar 4 месяца назад

    from where did you learn to use riverpod?

    • @andreiIupsa
      @andreiIupsa  4 месяца назад

      The getting started documentation they provide is all you need.

  • @AbdulHaseeb-sy7uo
    @AbdulHaseeb-sy7uo 4 месяца назад

    You made my day, letting me know what is possible with flutter! thank you so much Andrei .
    I have subbed your channel!

  • @rodrodrigues1729
    @rodrodrigues1729 4 месяца назад

    being creative is essential for programming, nicely done. the end of the video is really cool as well.

  • @michaelchiz8055
    @michaelchiz8055 4 месяца назад

    Nice

  • @koteelok2014
    @koteelok2014 4 месяца назад

    lazy

  • @matthieupernelle8074
    @matthieupernelle8074 4 месяца назад

    Can you translate a Js or Java library to dart with ChatGPT ?

  • @prabalverma334
    @prabalverma334 3 месяца назад

    good

  • @gauravjoshi747
    @gauravjoshi747 4 месяца назад

    can you open source it so that we can learn and contribute to it

  • @ebitdaddyca3676
    @ebitdaddyca3676 4 месяца назад +1

    Nice format, nice editing, nice app

    • @andreiIupsa
      @andreiIupsa  4 месяца назад

      Thank you 😃

    • @leoingson
      @leoingson 4 месяца назад

      +1, stole my comment :)

  • @momshaddinury
    @momshaddinury 4 месяца назад

    This is amazing, genius. By any chance is it possible to render math equation like calculus natively without using webview?

    • @andreiIupsa
      @andreiIupsa  4 месяца назад

      The runtime runs natively and doesn't use a webview, as far as I know.

    • @momshaddinury
      @momshaddinury 4 месяца назад

      @@andreiIupsa Do you need to render complex LaTeX formatted equations?

  • @nonefvnfvnjnjnjevjenjvonej3384
    @nonefvnfvnjnjnjevjenjvonej3384 4 месяца назад

    would react native be a better choice here? for easier js interop?

    • @sqrlware
      @sqrlware 4 месяца назад +1

      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.

  • @agoshxyz
    @agoshxyz 4 месяца назад +1

    All you need is React Native

  • @derismekentz1
    @derismekentz1 4 месяца назад

    most underated ending ever

  • @kevinmore2012
    @kevinmore2012 4 месяца назад

    I mean, you could have put those advanced calculations into a backend and only let paid members to access it.