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