Skip to content

Instantly share code, notes, and snippets.

@AndroidPoet
Created April 17, 2026 17:28
Show Gist options
  • Select an option

  • Save AndroidPoet/897b1546de01d1f54b27a1678cc6dd1c to your computer and use it in GitHub Desktop.

Select an option

Save AndroidPoet/897b1546de01d1f54b27a1678cc6dd1c to your computer and use it in GitHub Desktop.
sealed class Route {
data object ImageList : Route()
data object ImagePicker : Route()
}
@Composable
fun ImageListScreen(navController: NavController) {
var selectedImage by remember { mutableStateOf<String?>(null) }
val pickedImage = navController.currentBackStackEntry
?.savedStateHandle
?.getStateFlow<String?>("picked_image", null)
?.collectAsState()
LaunchedEffect(pickedImage?.value) {
pickedImage?.value?.let { image ->
selectedImage = image
Log.d("ImageList", "Received image: $image")
}
}
Column {
if (selectedImage != null) {
AsyncImage(model = selectedImage, contentDescription = null)
}
Button(onClick = { navController.navigate(Route.ImagePicker) }) {
Text("Pick Image")
}
}
}
@Composable
fun ImagePickerScreen(navController: NavController) {
val images = listOf(
"https://example.com/image1.jpg",
"https://example.com/image2.jpg",
"https://example.com/image3.jpg"
)
LazyVerticalGrid(
columns = GridCells.Fixed(3),
modifier = Modifier.fillMaxSize()
) {
items(images) { imageUrl ->
AsyncImage(
model = imageUrl,
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.clickable {
navController.previousBackStackEntry
?.savedStateHandle
?.set("picked_image", imageUrl)
navController.popBackStack()
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment