Brett Best
09/08/2020, 8:23 AMBrett Best
09/08/2020, 8:23 AM@Composable
fun LegalBodyContent(contentPadding: InnerPadding = InnerPadding(), onLegal: () -> Unit) {
val viewModel: MyViewModel = viewModel()
val user = viewModel.user.observeAsState()
Text(text = "${user.value}")
}
class MyViewModel: ViewModel() {
private val userId: LiveData<String> = MutableLiveData()
val user = userId.switchMap { id ->
liveData {
while(true) {
emit("Test string")
delay(30_000)
}
}
}
}
satyan
09/08/2020, 8:47 AMuserId
value anywhere ?Brett Best
09/08/2020, 8:48 AMemit("Test string")
, would set it?satyan
09/08/2020, 8:49 AMBrett Best
09/08/2020, 8:50 AMBrett Best
09/08/2020, 8:50 AMsatyan
09/08/2020, 8:51 AMsatyan
09/08/2020, 8:52 AMBrett Best
09/08/2020, 8:52 AMsatyan
09/08/2020, 8:56 AMval user = livedata{}
And load and emit your user inside the livedata block.Brett Best
09/08/2020, 8:57 AMsatyan
09/08/2020, 8:58 AMBrett Best
09/08/2020, 8:59 AM