Trying to use Flow for the first time for a piece of app state. my app state is basically whether or not the user is logged in.
I'm creating my flow this way
@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?