I just started using kodein for a desktop compose ...
# kodein
y
I just started using kodein for a desktop compose project, I'm getting a "missing DI container" error. What can be causing this?
b
Did you initialise the di container higher up the composable tree?
You need to wrap your app in withDi() composition local provider
y
yeah I tried that and it didnt work
Copy code
@Composable
@Preview
fun App() = withDI {

    //TODO: Initial screen to enter balance, check if balance is null then show the screen
    //TODO: find way other than flow or make flow work with one value to auto update balance
    MaterialTheme {
        Navigator(InitialScreen)
    }
}
also since I'm trying everything
val di: DI = Kodein.di
@Composable
Copy code
@Preview
fun App() = withDI(di) {

    //TODO: Initial screen to enter balance, check if balance is null then show the screen
    //TODO: find way other than flow or make flow work with one value to auto update balance
    MaterialTheme {
        Navigator(InitialScreen)
    }
}
b
Which part is throwing the error for you? I see no di access in either of the snippets
y
Copy code
object InitialScreen : Screen {

    override val key: ScreenKey = uniqueScreenKey

    @Composable
    override fun Content() {
        val viewModel = rememberScreenModel<InitialScreenModel>()
        Column(
            modifier = Modifier.fillMaxSize(),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text("Initial")
        }
    }

}
the viewmodel line
im using voyager but i also tried the normal kodein way with the same error
val viewModel: InitialScreenModel by rememberDI { instance() }
b
Hmm, I suspect it might have to do something with di calls being made inside and overriden fun. Otherwise your setup should work.
y
rememberScreenModel has to happen in a composable and this is how the voyager documentation has it 😞 Well time to try yet another navigation library. Thank you so much for your time!
had to downgrade kodein to 7.11 from 7.12 and it worked. In case anyone faces problems in the future
b
Hmm, smells like compose/kotlin version mismatch
Kodein probably bumped one of those too high 😀
r
7.11 uses Kotlin 1.6.10 with JB Compose 1.1 alpha 7.12 uses Kotlin 1.6.21 with JB Compose 1.2 alpha For Compose. we only test that Compilation works. if there is no Compose version with Kotlin version available we drop the support for Compose and republish a patch when Compiler plugin aligns
👍 1
y
Thank you