Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SavedStateHandle with empty keys in Android. works fine on desktop And Ios #2098

Open
dhvanil-infotech opened this issue Dec 31, 2024 · 0 comments

Comments

@dhvanil-infotech
Copy link

dhvanil-infotech commented Dec 31, 2024

Describe the bug
Navigation Arguments are not appearing in viewModel savedStateHandle in Android device

To Reproduce
DI Impl
viewModelOf(::BatchDetailViewModel)

init in composable
val viewModel = koinInject(parameters = { parametersOf(navBackStackEntry.savedStateHandle) })

class BatchDetailViewModel(
savedStateHandle: SavedStateHandle,
) : ViewModel() {

private val batchId = try {
println(savedStateHandle.keys())
savedStateHandle.get("json")?.toInt()?: 0
} catch (e: Exception) {
println("BatchId Error : ${e.message}")
0
}
}

Expected behavior
This implementation works fine in Desktop and Ios but it get empty Keys in Android

Koin module and version:
Koin Bom 4.1.0-Beta3

Snippet or Sample project to help reproduce
Screen(AppScreens.BatchDetailScreen.route) { navBackStackEntry ->
val viewModel = koinInject(parameters = { parametersOf(navBackStackEntry.savedStateHandle) })
val uiState by viewModel.uiState.collectAsState()
BatchDetailScreen(uiState = uiState, interActor = viewModel.interActor)
}

screens.forEach { screen ->
composable(
route = "${screen.route}?json={json}",
arguments = listOf(navArgument("json") {
type = NavType.StringType
defaultValue = ""
})
) { backStackEntry ->
screen.content(backStackEntry)
}
}

@dhvanil-infotech dhvanil-infotech changed the title SavedStateHandle with empty keys in Android. works fine on desktop SavedStateHandle with empty keys in Android. works fine on desktop And Ios Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant