Home > database >  How to load remote SVG image using Coil in Jetpack Compose
How to load remote SVG image using Coil in Jetpack Compose

Time:09-30

I'm failing to load this image in Image using Coil in Jetpack Compose

CodePudding user response:

Coil doesn't support SVG by default.

According to documentation, you need to:

  1. Add following dependency:

    implementation("io.coil-kt:coil-svg:$coil_version")
    
  2. Set SvgDecoder as decoder:

    rememberImagePainter(
        data = svgImageUrl,
        builder = {
            decoder(SvgDecoder(LocalContext.current))
        }
    ),
    

p.s. note that if you set the decoder this way, Coil will not be able to work with non-SVG images in this painter, so if you want some general solution, you should check the url extension and add the decoder accordingly.

  • Related