1

I am following an online tutorial on Loading Images using Coil Library in a Compose project.

The instructor has used this code snippet to load an image from an API:

    Image(
                painter = rememberImagePainter(data = trackedFood.imageUrl, builder = {
                    crossfade(true)
                    error(R.drawable.ic_burger)
                    fallback(R.drawable.ic_burger)
                }) ....

}

While I understand the use of the crossfade, placeholder and error features, I haven't understood the need for the fallback feature thus this question.

I have read the Coil docs but it doesn't explain what fallback feature does and I am now seeking a clarification.

Tonnie
  • 4,865
  • 3
  • 34
  • 50

1 Answers1

3

If the data param is null when you initialize rememberImagePainter it will load the image from the fallback params, which can be an Id or Drawable. I'm not sure if it's only the data param is null or also when the image byte received from the server is null that will trigger this fallback in case of the image received from the internet(http/https).

Dharman
  • 30,962
  • 25
  • 85
  • 135
axelbrians
  • 316
  • 4
  • 7