我的摇篮
// Coil
implementation "io.coil-kt:coil-compose:1.4.0"
问题描述
以前我将线圈与 Google 一起使用accompanist
,但是当我迁移到新版本的线圈时,如文档所示,我遇到了该target
方法的问题:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 13502
java.lang.IllegalArgumentException: request.target must be null.
at coil.compose.ImagePainterKt.rememberImagePainter(ImagePainter.kt:94)
...
线圈实现
在浏览(线圈类)的内部代码时,ImagePainter
您可以看到由于target
某种原因该方法确实需要为空:
@Composable
fun rememberImagePainter(
request: ImageRequest,
imageLoader: ImageLoader,
onExecute: ExecuteCallback = ExecuteCallback.Default,
): ImagePainter {
requireSupportedData(request.data)
require(request.target == null) { "request.target must be null." }
...
我的代码
这是我在 jetpack compose 中的组件(图像组件位于列内):
Image(
modifier = Modifier
.size(120.dp)
.align(Alignment.CenterHorizontally),
painter = rememberImagePainter(
data = entry.imageUrl,
builder = {
crossfade(true)
target {
viewModel.calcDominantColor(it) { color ->
dominantColor = color
}
}
transformations(CircleCropTransformation())
},
),
contentDescription = entry.pokemonName
)
viewModel
我需要目标方法根据drawable
它作为参数传递来对我进行内部操作。有人能帮我吗?