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

Unable to load Image using coil3 composed: AsyncImage

I’m learning Composed and tried to load an image from the internet using coil3.

@Composable
fun Test() {
    val imageUrl = "https://www.gstatic.com/webp/gallery/4.jpg"
    val imageRequest = ImageRequest.Builder(LocalPlatformContext.current)
            .data(imageUrl)
            .size(Size.ORIGINAL)
            .build()

    Surface (modifier = Modifier.fillMaxSize()) {
            AsyncImage(
                model = imageRequest,
                contentDescription = "Test Image",
                modifier = Modifier.fillMaxSize().size(80.dp),
                error = painterResource(R.drawable.resized_image_1) 
            )
    }
}

I also tried to use rememberAsyncImagePainter() but the image in the error is rendered
Permissions for internet is give.
Am i mission anything here
thanks

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

>Solution :

By default, Coil 3.x does not include support for loading images from the network. To add support for fetching images from the network import only one of the following:

implementation("io.coil-kt.coil3:coil-network-okhttp:3.0.4") // Only available on Android/JVM.
implementation("io.coil-kt.coil3:coil-network-ktor2:3.0.4")
implementation("io.coil-kt.coil3:coil-network-ktor3:3.0.4")

You can also use DebugLogger to get the error description:

internal class AppAplication: Application(), SingletonImageLoader.Factory {

    override fun newImageLoader(context: PlatformContext): ImageLoader =
        ImageLoader(context)
            .newBuilder()
            .logger(DebugLogger())
            .build()

}
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