1

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

1 Answer 1

1

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()

}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks 🙏, I was just focusing on this page coil-kt.github.io/coil/compose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.