Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

E/GlanceAppWidget: Error in Glance App Widget IllegalStateException: CompositionLocal LocalConfiguration not present

I am developing an app widget with compose. I have a problem with getting string from resources. If I give text as a string like text = "Label", it is working properly. But if I give with stringResource, text is not shown, and I see this problem. Is there anyone who has faced this issue? Thank you

E/GlanceAppWidget: Error in Glance App Widget
    java.lang.IllegalStateException: CompositionLocal LocalConfiguration not present
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.noLocalProvidedFor(AndroidCompositionLocals.android.kt:167)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.access$noLocalProvidedFor(AndroidCompositionLocals.android.kt:1)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$LocalConfiguration$1.invoke(AndroidCompositionLocals.android.kt:47)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$LocalConfiguration$1.invoke(AndroidCompositionLocals.android.kt:44)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:29)
        at androidx.compose.runtime.LazyValueHolder.getValue(ValueHolders.kt:31)
        at androidx.compose.runtime.ComposerImpl.resolveCompositionLocal(Composer.kt:1776)
        at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:1746)
        at androidx.compose.ui.res.StringResources_androidKt.resources(StringResources.android.kt:78)
        at androidx.compose.ui.res.StringResources_androidKt.stringResource(StringResources.android.kt:36)
class MarketWidget : GlanceAppWidget() {

    @Composable
    override fun Content() {
        Column(
            modifier = GlanceModifier
                .fillMaxSize()
                .background(color = Color.White)
                .padding(8.dp)
        ) {
            Text(
                text = stringResource(id = R.string.app_name)
            )
        }
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

stringResource is part of Compose UI, so you can’t use it in Glance. Glance’s Text only takes resolved strings, you can retrieve it using LocalContext.current.

To change your example, this should work:

Text(text = LocalContext.current.getString(R.string.app_name))

Also, ensure that you’re importing the Glance Text (androidx.glance.text.Text) and not the one from Material Compose UI (androidx.compose.material.Text)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading