Hey everyone! With Jetpack Compose, we’re able to ...
# compose
t
Hey everyone! With Jetpack Compose, we’re able to erase almost all use of LiveData (previously we used it to facilitate observing respecting the lifecycles). Yet we still use LiveData when using savedStateHandle in the ViewModel. Why is it that there isn’t a way to do this using Flow? For example, if we have a form with fields, we’ll usually write the logic for each field in the ViewModel like this (using savedStateHandle to keep the state in case of process death):
Copy code
val nameFieldLiveData = savedStateHandle.getLiveData(NAME_FIELD_KEY, "")
val nameFieldFlow: Flow<String> = maxPassengersLive.asFlow()

fun setNameField(name: String) {
   nameFieldLiveData.value = name
}
It would be great if there was a savedStateHandle.getFlow which returned a MutableStateFlow, right? Our main issue with LiveData is the fact that it holds a String! instead of a String. So in the case of my example, nameFieldFlow becomes a Flow<String!>, unless I specify the type explicitly. And I always forget to specify the type explicitly
☝🏼 1
☝🏾 1
☝️ 4
Maybe we’ll get a
androidx:savedstatehandle-flow
artifact, who knows 😛
😂 1
🦜 2