I am writing this blog post to keep my thoughts in order ! because, true to my nature, I will keep questioning this choice and I will end up going back and forth between writing code in Kotlin and Dart-Flutter, which is not good, because I end up with software that is not uniform, as usual
After reading a book on flutter, and a book on Kotlin multi platform, It looks like it is going in the direction of flutter, It is true that KMP – iOS is now in beta, and things should now be looking good for KMM and KMP, it is not a no brainier and here is why I decided to go with Flutter
First of all, I understand that flutter may or may not lose google’s support any minute now, this is true because google loves to abandon projects, so they just might, everyone online is saying that there are no signs of google dropping support, but the truth is, I can see the effort being put into Jetpack compose and compare it to Flutter, in any case only upper management at google may (or may not) know yet, In any case, Flutter is open source, and even if they drop support today, it will probably still work many years from now, and when it doesn’t, I have never had problems learning new languages in a couple of weeks.
I have been a C++ developer for 25 years, and earlier this year (It is still 2024 right ?), I started learning RUST, the start was hell, my inner child did not want to leave the comfort zone, and kept making up reasons why C++ is eternal and better than RUST, but after some time, I was convinced that we crossed the point of no return, and I started, slowly but steadily to fall in love with RUST.
Now RUST excels in front end and graphical user interfaces (Said no one ever)…. But if I am planning to run rust on Android or iOS, boy oh boy, I might have to reinvent computers
So, the answer is that the front end should be handled by either Dart-Flutter or Kotlin-Multi platform
Now, Why dart-flutter rather than Kotlin Multi Platform and Compose Multi Platform
Before I dive into this, the parts of the application that are expected to require performance are probably going to be written in RUST, while permissions and GUI are expected to be handled by flutter, So why flutter
1- Leaf calls, that is, Leaf calls will not permit the garbage collector to run, which means that it is safe to pass a pointer to underlying data to C, provided that C does not hold on to that pointer after the FFI call returns. This removes the need to copy the data before passing it to C. But we are not planning to use C, we are interested in RUST ! the answer is that this is a proof of concept, also “opaque types” are possible 😉
Ownership and lifetimes in FFI are probably more of a problem in Kotlin as it stands today ! this is because flutter_rust_bridge provides a level of abstraction to avoid dangling pointers etc….
In Kotlin, exposing Rust functions as C-compatible functions will have a library one day (We already have UniFFI ( UniFFI-RS by mozilla ) but it is not as mature, there are variants of this library to do the job, and for kotlin multiplatform it is here (uniffi-kotlin-multiplatform-bindings) also worth mentioning that there is a UniFFI variant for Dart-Flutter !
Rust code will interact with the Android Java APIs through the Java Native Interface (JNI), and only partly controlled by flutter, there is also no reason to assume that a lot of data is going to travel between dart and RUST in most applications, but when there is such a scenario, we know what to do, we chose flutter.