线圈不使用 Jetpack Compose 在模拟器中加载图像

时间:2021-07-30 00:49:34

标签: android android-jetpack-compose coil

我需要使用 Coil 通过 url 在我的应用程序中显示图像,但无法加载此图像。我遵循官方文档 https://coil-kt.github.io/coil/compose/

profile card

implementation "io.coil-kt:coil-compose:1.3.1"
@Composable
fun ProfilePicture(profilePicture: String, online: Boolean) {
    Card(
        shape = CircleShape,
        border = BorderStroke(
            width = 2.dp,
            color = if (online) MaterialTheme.colors.lightGreen else Color.Red
        ),
        modifier = Modifier.padding(16.dp),
        elevation = 4.dp
    ) {
        Image(
            painter = rememberImagePainter(
                data = profilePicture,
                builder = {
                    transformations(CircleCropTransformation())
                }
            ),
            modifier = Modifier.size(72.dp),
            contentDescription = "Profile picture"
        )
    }
}

更新

UserModel 示例

UserModel(
    name = "John Doe",
    profilePicture = "https://randomuser.me/api/portraits/men/32.jpg",
    online = true
)

0 个答案:

没有答案