Показать isloading = false и перезагрузить данные профиля после входа.
Код: Выделить всё
class ProfileViewModel(
private val userInfoApi: UserInfoApi,
private val logoutApi: LogoutApi,
) : ViewModel() {
private val eventChannel = Channel
()
val events = eventChannel.receiveAsFlow()
var profileUiState = flow {
val result = userInfoApi.getUserInfo()
emit(
result.fold(
onSuccess = {
ProfileUiState(userInfo = it, isLoading = false)
},
onFailure = {
ProfileUiState(errorMessage = it.message, isLoading = false)
}
)
)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.Lazily,
initialValue = ProfileUiState(isLoading = true)
)
fun onAction(action: ProfileUiEvent) {
viewModelScope.launch {
eventChannel.send(action)
}
}
fun logoutUser() {
viewModelScope.launch {
// update the logic in here for logout
profileUiState
}
}
}
calling getUserinfo () Inside init {} of viewModel. Вызов.>
Подробнее здесь: https://stackoverflow.com/questions/795 ... ck-compose