Created
January 4, 2026 08:57
-
-
Save skydoves/a95be9d8c50bb6455097d3b8c0b37c3c to your computer and use it in GitHub Desktop.
Landscapist: Loading Images with Flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.skydoves.landscapist.core.ImageRequest | |
| import com.skydoves.landscapist.core.model.ImageResult | |
| suspend fun loadImage(url: String) { | |
| val request = ImageRequest.builder() | |
| .model(url) | |
| .size(width = 800, height = 600) | |
| .build() | |
| landscapist.load(request).collect { result -> | |
| when (result) { | |
| is ImageResult.Loading -> { | |
| println("Loading...") | |
| } | |
| is ImageResult.Success -> { | |
| val imageBitmap = result.data | |
| val dataSource = result.dataSource // MEMORY, DISK, or NETWORK | |
| println("Loaded from: $dataSource") | |
| } | |
| is ImageResult.Failure -> { | |
| val error = result.reason | |
| println("Error: ${error.message}") | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment