https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

Gunslingor

04/10/2020, 7:21 PM
Has anyone made a multiplatform app that utilizes flutter? Been doing my front ends in flutter last few days and I'm liking it, need to combine it with my ktor server stuff for the same product so I can have unified codebase, git, maybe common kotlin lib later, etc. Wondering if there is a recommended way to do that.
s

spierce7

04/10/2020, 8:26 PM
Flutter is great. Dart is horrible though. It creates a new problem that I like to call
Constructor Hell
.
g

Gunslingor

04/10/2020, 8:27 PM
explain 😃
it feels like programming for elementary schoolers for me, lol, but it works and has a solid base of tools and docs... they definitely need to go the way of python and use indents instead of constant () or {}
s

spierce7

04/10/2020, 8:45 PM
const
is really annoying. The compiler should do that for you.
If you create any level of complicated View heirarchy, and then try to edit it, it becomes REALLY annoying.
g

Gunslingor

04/10/2020, 8:47 PM
hmmmmmm
s

spierce7

04/10/2020, 8:47 PM
They have a plugin that helps with that in the IDE, but it’s still really annoying. They added a language feature so that you can build an
Array
and while building the array have
if/else
blocks inside of it to conditionally add things in the
Array
. It’s still very painful using that stuff, and what you really want is a proper DSL
g

Gunslingor

04/10/2020, 8:50 PM
hmm... maybe it depends what your making... it seems to do so much for you. Like I made a recycler view with picasso and rss feed reading in android, then I made the same thing flutter. flutter took about 8 times less time and resulted in code I actually could 100% understand, 100% is an accomplishment.
s

spierce7

04/10/2020, 8:50 PM
Flutter, which is pretty great, is propping up a failed language that has been rejected by multiple communities multiple times. The worst case scenario imo is that Dart starts being used because of Flutter. I’d much rather the flutter team switch to a more competent language. I’d probably use it if they did, especially if it was Kotlin.
g

Gunslingor

04/10/2020, 8:51 PM
Yeah, I do agree... dart is not so special imo
s

spierce7

04/10/2020, 8:51 PM
@Gunslingor So that’s Flutter’s reactive view declaration. It’s fantastic. Android is getting something similar called jetpack compose, only it’s in a proper DSL, not constructor Hell.
g

Gunslingor

04/10/2020, 8:53 PM
By constructor you mean actual functional constructors? lol, I don't find it hellish... to me dart uses a fuck load or () and kotlin uses a fuck load of { }, otherwise its just basically assignment.
s

spierce7

04/10/2020, 8:53 PM
Jetpack Compose will be even better than Flutter’s UI lib imo as it will use a proper DSL meaning you won’t be limited by constructors. Flutter still lets you do cross platform though. We’ll see if the community or anyone makes Jetpack compose multiplatform.
g

Gunslingor

04/10/2020, 8:55 PM
Yeah... I've never been a big fan of extending off someone elses library unless they are real extension libraries... it's useful but gets confusing as hell, especially when the drill down ends in there compiled code.
s

spierce7

04/10/2020, 8:56 PM
@Gunslingor in Flutter let’s say you have a Row of Columns, which all have Rows of Text (a relatively simple example), and then you decide you want to put the Rows each in a
Center
widget. Things quickly start to become difficult to manage.
Editing View Heirarchies is terrible
the IDE shortcuts that they added for this become essential.
g

Gunslingor

04/10/2020, 8:57 PM
agreed, the IDE tools make fllutter something I consider pretty special so far... so far being 24 hours... but I've had 6 months with Kotlin, deep.
yeah, I need to see how dart evolves... keep componentizing stuff
k

Kweku

04/10/2020, 11:57 PM
This my plan too. Basically Flutter communicates with the native app via platform channels, the two main ones being method channel(flutter calling native functions and vice versa) and event channels( basically streams). So basically flutter links with your KMP library via the platform channels in your android or IOS app
g

Gunslingor

04/11/2020, 1:57 AM
Not sure I follow, I'm just trying to figure out where to put folders, lol... two isolated idea projects, flutter and then ktor plus kotlin JS... but I want 1 git and ideally a master gradle file with some kind of multplatform + flutter plugin or something, would be nice to be able to kick the server and app emulators off together.
s

spierce7

04/11/2020, 2:03 AM
I think there is a very good chance that Flutter is abandoned in a few years. The Android team is considering converting jetpack libraries to Kotlin multiplatform (they asked several questions about how much this should be prioritized in the last developer survey). Also - certain parts of jetpack compose were written as multiplatform enabled. If the community, jetbrains, or even Google itself ports jetpack to competently to multiplatform, then that will seriously detracts from any value proposition that flutter offers, and I think outright kill it. I spent 2 months working on an app in Flutter. I ended up abandoning it because I started to hate maintaining it so much because Dart was really getting in my way, even though it was really easy to get started.
g

Gunslingor

04/11/2020, 2:12 AM
Yeah, no great options ATM if you ask me... never really ever have been, lol
s

spierce7

04/11/2020, 4:48 AM
react native is pretty good actually
s

Sam

04/11/2020, 1:33 PM
I’m a Kotlin/Swift dev by day and Flutter/Dart dev by night. I actually like Flutter and its productivity. I have a decent pattern down for taming the constructor hell. It boils down to don’t be afraid to make widgets or functions that return them. If you find you’re build functions are too big to fit on one screen, hit that refactor button. Definitely make use of the IDE tools to extract widgets or wrap in another widget. It saves a lot of time. All that said, I don’t think Flutter/Dart integrates well with Kotlin. The platform channels is one way but it is more for integration with the platform the app is running on. As a logic sharing mechanism I think you would be disappointed. You’re currently limited to sending over primitives, dictionaries and arrays. You would end up writing a wrapper lib in dart for your KMP lib to make it look decent on the Flutter side. All of your wrapper methods would have to be marked as async which can introduce awkwardness in your Flutter code. You could possibly use FFI and have Dart treat your lib like a C library. I haven’t tried it but I suspect that K/N’s memory model will impose a lot of constraints on your code since the Dart garbage collector will try to access your objects on a background thread. I’ve done a POC for this with JavaScript Core on iOS. It’s possible but tedious.
g

Gunslingor

04/12/2020, 6:13 AM
hmm... interesting. Well, sharing code from js/jvm/common kotlin and flutter dart is a secondary goal, tertiary actually... ATM, I'm trying to figure out how I can make these two projects into one, mainly for version control... so really my goals are: 1) merge the flutter app INTO the jvm/js/common app somehow for VCS since that one already has git history, 2) Be able to build, test and run both with a single button click for each (hopefully using gradle, to bring the projects together from a tasks perspective) 3) code sharing. I guess I could make my life easier by just keeping the projects separate and pressing two buttons instead of one, lol, its just all one project for one company so would be nice to keep it together... especially considering github doesn't offer folders or any way to organize multiple repos without paying for each folder, bastards!
Any further advice on this one? I haven't brought myself to create a second git repo.
k

Kweku

04/22/2020, 2:12 PM
@Sam I think the best way is to create a flutter project then and the kmp library as a submodule of android on the same level as the app module Project -Android --app ---build.gradle(for android app) --common(kotlin multiplatform) ---build.gradle(for kmp) --build.gradle(top level for entire project) --settings.gradle -ios -lib I did mine like this Project -Android --app ---build.grade -common --build.grade.kts -lib -iOS build.gradle.kts settings.grade.kts And am having issues because it is trying to find the manifest in android/ instead of android/app/src/main so I advise the first way
g

Gunslingor

04/22/2020, 2:35 PM
hmmm.... interesting, thanks, I'll review that in deeper detail this week. Initially the main thing I am noticing about this example is that there are tons of different projects of different types and on different folder levels, this is in and of itself is what I need to learn and become an expert on, then figure out how to work it into my existing git; doubt he is using git submodules. Like I mentioned the main issue, issue 1, is combining these projects for git purposes without losing history of the existing one... and to do it in such a way to just prepare and not exclude the possibly of code sharing later if that makes sense. So finally seeing a single git repo with so many many projects gives me some hope; honestly the rest seems more solvable once that is addressed... I mean, I know what I think I want, I just don't know if it's achievable or tough or not recommended... I mean you said "And am having issues because it is trying to find the manifest in android/ instead of android/app/src/main so I advise the first way"... me TOO!!! Constantly!!! many different gradle plugins seem to not allow the user to modify default pathing, which really is unacceptable IMHO but what can I do about it. So, I think want this setup: Project web (slightly modified but still isolated ktor/kotlinJS project) app (normal isolated flutter app) .git build.gradle.kts (want to be able to kick off the web and app builds from here, will have iOS laptop in a few months and would like to be able to compile on that over the same network, but do it by kicking off a task in this master gradle file from MY WINDOWS machine... kicking the entire company build process off from a single gradle task is goal 2 with minimal apple involvement, goal 3 is less critical but is code sharing via kmp library)
k

Kweku

04/22/2020, 7:05 PM
OK managed to fix the manifest issue thanks to this https://github.com/flutter/flutter/issues/33762 basically when you try to launch your flutter app it checks I the android module has a build.gradle file, if not it defaults to looking for the manifest in android/. So just create android/build.gradle and it's contents should be just apply from: "path to project gradle file" in my case it's "../build.gradle.kts" So I now have this working Project -Android --app ---build.grade --build.grade(the new grade file) -common --build.grade.kts -lib -iOS build.gradle.kts settings.grade.kts
6 Views