Thread
#compose
    m

    MaxUt

    1 year ago
    Is there a way to hide an image that couldn't be loaded with Coil ? I've tried using the onExecute function but the states always seems to be EMPTY. Note that I have set a height to my Image composable which is why I want to hide it if it fails.
    Vadzim Filipovich

    Vadzim Filipovich

    1 year ago
    You could render an image if state flag is true, so you could create a custom image composable, inside this composable you have state //isError//, and if isError false - display image, if not - display nothing. On coil error callback you could set isError to true
    Colton Idle

    Colton Idle

    1 year ago
    val painter = rememberImagePainter("http")
    val state = painter.state
    if (state is ImagePainter.State.Loading) {
        
    } else {
        Image(
            painter = painter,
            modifier = Modifier.size(48.dp)
        )
    }
    does this help?
    Vadzim Filipovich

    Vadzim Filipovich

    1 year ago
    @Colton Idle notice, that state could be error and it will fall back to else
    Colton Idle

    Colton Idle

    1 year ago
    Use
    ImagePainter.State.Error
    instead?
    Vadzim Filipovich

    Vadzim Filipovich

    1 year ago
    Yep
    m

    MaxUt

    1 year ago
    Thank you guys 🙂 I ended up using
    @Composable
    fun ImageWrapper(painter: ImagePainter, content: @Composable () -> Unit) {
        if (painter.state is ImagePainter.State.Success || painter.state is ImagePainter.State.Empty) {
            content()
        }
    }