How do I troubleshoot why Preview annotation isn't...
# compose
j
How do I troubleshoot why Preview annotation isn't working in my project? It does work on very simple UIs, where I show a text box, for example, that is hard-coded. I am using Kotlin 1.6.10 on compose 1.2.0-alpha07
c
If you click that blue Info icon in the top right of the Preview window that opens a panel where the error message shows up.
What version of Android Studio are you using?
j
Bumblebee is the version. java.lang.IllegalStateException: KoinApplication has not been started at org.koin.core.context.GlobalContext.get(GlobalContext.kt:36) at com.blackfox.myoutfitpicker.android.ui.AnonymousSendScreenKt.AnonymousSendScreen(AnonymousSendScreen.kt:93) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
j
it’s because you’re attempting to use your DI injector on the preview instead of having
val viewModel: MyOutfitPickerViewModel by inject()
inside the composable function body, I would provide it as a parameter, and then you can use a
PreviewParameterProvider
to pass in a mock/fake viewModel
👍 1
c
Ah yes. Preview doesn't support DI yet. Though I think we should make that clearer with error messaging