#koin-annotations Hey folks, do I need to do anyt...
# koin
p
#koin-annotations Hey folks, do I need to do anything extra to use
SavedStateHandle
in a
@KoinViewModel
injected in a
composable
function? Version
Copy code
koin-bom = "4.1.0"
koin-annotations = "2.1.0"
kotzilla = "1.2.0-Beta1"
kotzillaPlugin = "1.2.0-Beta2"
Caused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'androidx.lifecycle.SavedStateHandle'. Check your Modules configuration and add missing type and/or qualifier!
When I remove the
SavedStateHandle
from my ViewModel, everything works fine.
1
k
@Pedro Francisco de Sousa Neto share your VM setup
a
with Compose it should be ok on Android. Else SavedStateHandle is not fully supported on iOS
p
Sure, @Kibet Theophilus! I will already send in channel to improve the snippet code readability. ViewModel
Copy code
@KoinViewModel
class MyViewModel(
    private val getUsers: GetUsers,
    private val savedStateHandle: SavedStateHandle
) : ViewModel(), StateMachine<UserListIntent, UserListState>
Compose
Copy code
@Composable
fun MyScreen(
    viewModel: MyViewModel = koinInject(),
) {
    val state by viewModel.state.collectAsState()

    LaunchedEffect(Unit) {
        viewModel.dispatch(UserListIntent.LoadUsers)
    }

    [...]
}
1
a
> viewModel: MyViewModel = koinInject(), use koinViewModel()
1
p
Yeah, it's an Android projet @arnaud.giuliani.
👍 1
a
koinViewModel() will trigger injection of SavedStateHandle, not koinInject()
koin parrot 1
p
You solved it, @arnaud.giuliani. Thank you!
🙏 1