Can Korkmaz
02/22/2022, 2:30 PMval suIdKeyFlow = dataStore.data.map { // this is dataStoreRepository class member
it[PreferenceKeys.suIdKey] ?: 0
}
ViewModel member function:
private suspend fun readSuId(){
storeRepository.suIdKeyFlow.collect {
currentUserSuId.value = it
Log.d("main", "current user su id flow: ${currentUserSuId.value}") // log is printed to logcat
}
}
ViewModel init block:
init {
Log.d("main","Main View Model created")// this gets printed to logcat
viewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>){
Log.d("main","inside viewmodel coroutine scope 1")// this also gets printed to logcat
readSuId()
Log.d("main","inside viewmodel coroutine scope 2: --> ${currentUserSuId.value}}")// can't observe this log at logcat
if(currentUserSuId.value != 0){
getCurrentUser(currentUserSuId.value)
}
}
isUserLoggedIn()// this sets isLoggedIn mutableState<Boolean> in viewmodel, and observed at composable for automatic login, not necessarily related to problem
Log.d("main", " user logged in : ${userLoggedIn.value}")
Tim Oltjenbruns
02/22/2022, 6:04 PMCan Korkmaz
02/23/2022, 7:55 AMTim Oltjenbruns
02/23/2022, 12:44 PM