-
-
Save PatilShreyas/4d6a402efd0c98c7509252debc3ed9cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A state model for Login screen | |
data class LoginState( | |
val isLoading: Boolean = false, | |
val loggedInUser: User? = null | |
val error: String? = null | |
) | |
class LoginViewModel(...) : ViewModel() { | |
// Individual state flows | |
private val isLoading = MutableStateFlow(false) | |
private val loggedInUser = MutableStateFlow<User?>(null) | |
private val error = MutableStateFlow<String?>(null) | |
// Combining these states to form a LoginState | |
val state: StateFlow<LoginState> = combine(isLoading, loggedInUser, error) { loading, user, errorMessage -> | |
LoginState(loading, user, errorMessage) | |
}.stateIn(viewModelScope, WhileObserved(), initialValue = LoginState()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment