New to Jetpack Compose and Coil, but not new to Android or Java/Kotlin.
I'm not able to show images from a URL...Something basic missing?
I took the Google/Android tutorial from (https://developer.android.com/jetpack/compose/tutorial) and added to the gradle script:
implementation("io.coil-kt:coil:2.0.0-rc03")
implementation("io.coil-kt:coil-compose:2.0.0-rc03")
And I added a String url to the Messages:
data class Message(val author: String, val url: String, val body: String)
and added URLs to the sample data:
Message(
"Colleague",
"http://martypants.us/images/person4.png",
"Searching for alternatives to XML layouts..."
)
And in my @Composable, I changed it to use an AsyncImage to load the URL instead of a drawable
@Composable
fun MessageCard(msg: Message) {
Row {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(msg.url)
.build(),
placeholder = painterResource(R.drawable.ic_profile),
error = painterResource(R.drawable.ic_error),
contentDescription = stringResource(R.string.description),
contentScale = ContentScale.Fit,
modifier = Modifier
// Set image size to 40 dp
.size(40.dp)
.width(48.dp)
.height(48.dp)
// Clip image to be shaped as a circle
.clip(CircleShape)
.align(Alignment.CenterVertically)
.border(1.5.dp, MaterialTheme.colors.secondary, CircleShape)
)
}
When I run it, it doesn't load the image. I verified the image exists, is readable, etc. I only see the error placeholder, and I never see any errors in Logcat.
Lots of other tutorials show similar usage, but can't' seem to figure out why my images are not loaded. What am i missing?
https
URL and see if you have better luck. – Inducement