https://kotlinlang.org logo
#kodein
Title
# kodein
y

Yousef

07/25/2022, 8:57 PM
I just started using kodein for a desktop compose project, I'm getting a "missing DI container" error. What can be causing this?
b

Big Chungus

07/25/2022, 9:20 PM
Did you initialise the di container higher up the composable tree?
You need to wrap your app in withDi() composition local provider
y

Yousef

07/26/2022, 6:10 PM
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

Big Chungus

07/26/2022, 6:13 PM
Which part is throwing the error for you? I see no di access in either of the snippets
y

Yousef

07/26/2022, 6:14 PM
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

Big Chungus

07/26/2022, 6:26 PM
Hmm, I suspect it might have to do something with di calls being made inside and overriden fun. Otherwise your setup should work.
y

Yousef

07/26/2022, 6:28 PM
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

Big Chungus

07/26/2022, 9:34 PM
Hmm, smells like compose/kotlin version mismatch
Kodein probably bumped one of those too high 😀
r

romainbsl

07/27/2022, 2:06 PM
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

Yousef

07/27/2022, 2:07 PM
Thank you
81 Views