Crash when using material3-window-size-class
Closed this issue · 2 comments
MostafaMohamed2002 commented
after i added
implementation("org.jetbrains.compose.material3:material3-window-size-class:1.7.1")
and set it up like this in android main
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val size = calculateWindowSizeClass(
activity = this@MainActivity
)
App(
windowSize = size
)
}
}
}
desktop main
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
fun main() = application {
val windowState = rememberWindowState(
size = DpSize(800.dp, 600.dp),
)
val size = calculateWindowSizeClass()
Window(
onCloseRequest = ::exitApplication,
title = "KMovies",
) {
App(
windowSize = size
)
}
}
i get this error
Error was captured in composition while live edit was enabled.
java.lang.IllegalStateException: CompositionLocal LocalWindowInfo not present
at androidx.compose.ui.platform.CompositionLocalsKt.noLocalProvidedFor(CompositionLocals.kt:253)
at androidx.compose.ui.platform.CompositionLocalsKt.access$noLocalProvidedFor(CompositionLocals.kt:1)
at androidx.compose.ui.platform.CompositionLocalsKt$LocalWindowInfo$1.invoke(CompositionLocals.kt:194)
at androidx.compose.ui.platform.CompositionLocalsKt$LocalWindowInfo$1.invoke(CompositionLocals.kt:193)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:83)
at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:46)
at androidx.compose.runtime.LazyValueHolder.readValue(ValueHolders.kt:48)
at androidx.compose.runtime.CompositionLocalMapKt.read(CompositionLocalMap.kt:91)
at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:2375)
at androidx.compose.material3.windowsizeclass.WindowSizeClass_skikoKt.calculateWindowSizeClass(WindowSizeClass.skiko.kt:42)
at org.mostafadevo.kmovies.ComposableSingletons$MainKt$lambda$-125169687$1.invoke(main.kt:17)
at org.mostafadevo.kmovies.ComposableSingletons$MainKt$lambda$-125169687$1.invoke(main.kt:13)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:117)
at androidx.compose.ui.window.Application_desktopKt$application$1$1.invoke(Application.desktop.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:233)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1$1.invoke(Application.desktop.kt:232)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:223)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2$1.invoke(Application.desktop.kt:221)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jb.kt:33)
at androidx.compose.runtime.ActualJvm_jvmKt__ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:36)
at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(Unknown Source)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3595)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3522)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:743)
at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:1122)
at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:649)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:635)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:221)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:728)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:750)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
MostafaMohamed2002 commented
All Good , i made a mistake it should be like this
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
fun main() = application {
val windowState = rememberWindowState(
size = DpSize(800.dp, 600.dp),
)
Window(
onCloseRequest = ::exitApplication,
title = "KMovies",
state = windowState
) {
val size = calculateWindowSizeClass()
App(
windowSize = size
)
}
}
sellmair commented
Also please make sure to wrap your App() into a DevelopmentEntryPoint 😀