@Composable
fun DialogWithImage(
onDismissRequest: () -> Unit,
onConfirmation: () -> Unit,
painter: Painter,
imageDescription: String,
) {
Dialog(onDismissRequest = { onDismissRequest() }) {
// Use the Material dialog shape and color. The Card clips the image to its rounded corners.
Card(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
shape = MaterialTheme.shapes.extraLarge,
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
),
) {
Column {
// The image fills the full width of the dialog.
Image(
painter = painter,
contentDescription = imageDescription,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth()
.height(160.dp)
)
Text(
text = "This is a dialog with buttons and an image.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(start = 24.dp, top = 24.dp, end = 24.dp),
)
// Material dialogs align their actions to the end, 8.dp apart.
Row(
modifier = Modifier
.fillMaxWidth()
.padding(24.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End),
) {
TextButton(onClick = { onDismissRequest() }) {
Text("Dismiss")
}
TextButton(onClick = { onConfirmation() }) {
Text("Confirm")
}
}
}
}
}
}