Colton Idle
10/05/2021, 1:35 AM@Singleton
class AppUserManager
@Inject
constructor(@ApplicationContext val context: Context) {
var loggedInFlow = flow<Boolean> { false }
...
and then there is a login call in the appUserManager
fun login(token: String) {
loggedInFlow = flow { true }
...
}
then in my apps ViewModel I listen to this flow via
@HiltViewModel
class HomeScreenViewModel
@Inject
constructor(
var service: ApiService,
private val appUserManager: AppUserManager
) : ViewModel() {
init {
reload()
viewModelScope.launch { appUserManager.loggedInFlow.collect {
reload()
} }
}
...
This doesn't work. I'm assuming I'm missing something fundamental here about how to observe a flow. Any tips for me?Colton Idle
10/05/2021, 1:43 AMval loggedInFlow = MutableStateFlow<Boolean>(false)
collecting is the same. and I just call loggedInFlow.value = whatever and it just emits super easily.jw
10/05/2021, 3:20 AMjw
10/05/2021, 3:21 AMColton Idle
10/05/2021, 6:09 AM