You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specify the language of the codelab if it is not English:
english
In which task and step of the codelab can this issue be found?
task 6 and step 6
Describe the problem
I have followed the codelab and written the code as instructed.
When I load the app when the preference IS_LINEAR_LAYOUT is set to false, the app displays the linear layout for a second and then the grid. This is fixed in the solution code but the steps for the codelab code instructions need updating.
The differing code is in DessertReseaseViewModel.kt
Codelab code with issue:
// UI states access for various [DessertReleaseUiState]
val uiState: StateFlow<DessertReleaseUiState> =
userPreferencesRepository.isLinearLayout.map { isLinearLayout ->
DessertReleaseUiState(isLinearLayout)
}
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000L),
initialValue = DessertReleaseUiState()
)
Solution code:
val uiState: StateFlow<DessertReleaseUiState> =
userPreferencesRepository.isLinearLayout.map { isLinearLayout ->
DessertReleaseUiState(isLinearLayout)
}.stateIn(
scope = viewModelScope,
// Flow is set to emits value for when app is on the foreground
// 5 seconds stop delay is added to ensure it flows continuously
// for cases such as configuration change
started = SharingStarted.WhileSubscribed(5_000),
initialValue = runBlocking {
DessertReleaseUiState(
isLinearLayout = userPreferencesRepository.isLinearLayout.first()
)
}
)
I can see it's the initialValue code that needs to be changed.
Steps to reproduce?
Take the starter code and write the code that the codelab tells you to write.
Open the app, change the app to Grid mode
close the app and reopen
you can see it loads linear and then grid mode
Versions Android Studio version:
Android Studio Ladybug | 2024.2.1 Patch 3
API version of the emulator: Using my phone to run it, Android 14
Additional information Include screenshots if they would be useful in clarifying the problem.
The text was updated successfully, but these errors were encountered:
URL of codelab:
https://developer.android.com/codelabs/basic-android-kotlin-compose-datastore?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-6-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-datastore#6
Specify the language of the codelab if it is not English:
english
In which task and step of the codelab can this issue be found?
task 6 and step 6
Describe the problem
I have followed the codelab and written the code as instructed.
When I load the app when the preference IS_LINEAR_LAYOUT is set to false, the app displays the linear layout for a second and then the grid.
This is fixed in the solution code but the steps for the codelab code instructions need updating.
The differing code is in DessertReseaseViewModel.kt
Codelab code with issue:
Solution code:
I can see it's the initialValue code that needs to be changed.
Steps to reproduce?
Versions
Android Studio version:
Android Studio Ladybug | 2024.2.1 Patch 3
API version of the emulator: Using my phone to run it, Android 14
Additional information
Include screenshots if they would be useful in clarifying the problem.
The text was updated successfully, but these errors were encountered: