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
Chris Sinco [G]
04/17/2022, 9:31 PM
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.
Chris Sinco [G]
04/17/2022, 9:32 PM
What version of Android Studio are you using?
j
James Black
04/18/2022, 12:49 AM
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
james
04/19/2022, 12:49 AM
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
Chris Sinco [G]
04/19/2022, 7:30 AM
Ah yes. Preview doesn't support DI yet. Though I think we should make that clearer with error messaging