https://kotlinlang.org logo
#android
Title
# android
h

Haythem Drihmi

01/26/2023, 9:06 PM
Hello everyone, coming from Flutter community and Want to ask a Question. Is there any State management package / and what is the recommended way to store your state, for easy access and management? ( we have things like BLoC / providers / State containers ) is that the same for kotlin or using remember { mutable state of() } is the recommended approach?
😶 2
k

Kevin Del Castillo

01/26/2023, 9:55 PM
If you're developing only for Android, you'll want to go with MVVM or MVI with official Android components such as
ViewModel
, they couple well together with Compose, in this scenario Compose is only a UI framework, the data layer is separated you could even use the same code to create UI specific to Wear OS or Android TV. An alternative to the official guidance would be Molecule, that could be potentially used for Compose Multiplatform as well if I'm not mistaken.
p

Pablichjenkov

01/26/2023, 10:10 PM
Try googling/chat-gpting State Management in Android or State Management in Jetpack compose Android or State Management in compose UI? You probably gonna get richer information than a response here
k

kevindmoore

01/26/2023, 11:14 PM
I was wondering the same thing. MVVM is more of an architecture that a state management package. After reading several things about needing to be careful about state in compose, something other than just using remember everywhere would be nice
p

Pablichjenkov

01/26/2023, 11:35 PM
I did not want to comment since it is not specific to Kotlin but I agree on not abusing remember. I prefer hosting the state outside the Composable. Be it a ViewModel in jetpack navigation Navbackstackentry or a component in a solution like decompose.
c

chanjungskim

01/27/2023, 2:07 AM
Jetpack compose has remember stuffs for keeping views' state. and data classes for data. And this is MVI just like Flutter, I think. Non-jetpack compose users use MVVM pattern in common and it has ViewModel to keep the state and also bundle stuffs to keep the data even in the app crash.
👍 1
t

Tjerk Wolterink

01/27/2023, 8:31 AM
I think this user is talking about redux style state managememt. Which is not how android normally has it implemented. I’m sure you can find lobs but best to stick with the platform standards
a

Arkadii Ivanov

01/27/2023, 10:00 AM
You can check out Decompose for BLoC-like architecture - https://github.com/arkivanov/Decompose And MVIKotlin for MVI state management - https://github.com/arkivanov/MVIKotlin They both multiplatform in case you ever want to support other platforms.
👍 2
43 Views