Skip to content

Instantly share code, notes, and snippets.

@veroanggra
Created April 3, 2023 14:31
Show Gist options
  • Save veroanggra/697d86bc761f167902018d61395b48ca to your computer and use it in GitHub Desktop.
Save veroanggra/697d86bc761f167902018d61395b48ca to your computer and use it in GitHub Desktop.
@Composable
fun FavoriteButton(modifier: Modifier = Modifier) {
var favorite by remember { mutableStateOf(false) }
var color by remember { mutableStateOf(Color.Gray) }
color = if (favorite) {
Color.Red
} else {
Color.Gray
}
Image(Icons.Default.Favorite,
contentDescription = null,
colorFilter = ColorFilter.tint(color),
modifier = modifier
.size(200.dp)
.clickable {
favorite = true
if (color == Color.Red) {
favorite = false
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment