Basically, the problem I'm dealing with is that I have two screens: OnBoarding and login. When the user installs and opens the app for the first time I save true to indicate that it was the first time.
When the user opens the app more than once, it's intended to send them to the login screen, but first shows the onboarding screen for a few seconds and then navigates to the login screen, see the code below:
@Composablefun Navigation() { val navController = rememberNavController() val onBoardingViewModel = hiltViewModel<OnBoardingViewModel>() val isTheFirstTimeInstalled = onBoardingViewModel.onBoardingState.collectAsStateWithLifecycle() val startDest = getStartDest(isTheFirstTimeInstalled.value) NavHost( navController = navController, startDestination = startDest, enterTransition = { slideIn() }, exitTransition = { slideOut() }, ) { // some code }
OnBoardingViewModel:
@HiltViewModelclass OnBoardingViewModel @Inject constructor( private val dataStore: PreferencesDatastore) : ViewModel() { private val _onBoardingState = MutableStateFlow(false) val onBoardingState = _onBoardingState.asStateFlow() init { viewModelScope.launch(Dispatchers.IO) { _onBoardingState.value = dataStore.getOnBoardingState().first() } } fun setFirstTimeInstalled() { viewModelScope.launch(Dispatchers.IO) { dataStore.saveOnBoardingState(true) } }}
Is there any way to solve this problem? Let me know please!
I only tried to determine the start destination by calling my function "getStartDest" which basically gets the route