Created
February 9, 2022 12:52
-
-
Save merttoptas/ab0f88b0eac6ec5992a0e4f839c4b631 to your computer and use it in GitHub Desktop.
This file contains 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
@Composable | |
fun Plant(modifier: Modifier, plant: Plant) { | |
ConstraintLayout(modifier = modifier) { | |
val (image, title, description, checkbox, divider) = createRefs() | |
Image( | |
painter = rememberImagePainter(plant.image), | |
contentDescription = null, | |
modifier = Modifier | |
.size(64.dp) | |
.clip(MaterialTheme.shapes.small) | |
.constrainAs(image) { | |
top.linkTo(parent.top) | |
bottom.linkTo(parent.bottom) | |
start.linkTo(parent.start) | |
}, | |
contentScale = ContentScale.Crop, | |
) | |
Text( | |
text = plant.name, | |
modifier = Modifier | |
.constrainAs(title) { | |
top.linkTo(parent.top) | |
start.linkTo(image.end, margin = 16.dp) | |
} | |
.paddingFromBaseline(top = 24.dp), | |
style = MaterialTheme.typography.h2 | |
) | |
Text( | |
text = plant.description, | |
modifier = Modifier | |
.constrainAs(description) { | |
top.linkTo(title.bottom) | |
start.linkTo(title.start) | |
}, | |
style = MaterialTheme.typography.body1 | |
) | |
Checkbox( | |
checked = plant.isChecked, | |
onCheckedChange = { }, | |
modifier = Modifier.constrainAs(checkbox) { | |
top.linkTo(parent.top, margin = 16.dp) | |
bottom.linkTo(parent.bottom, margin = 24.dp) | |
end.linkTo(parent.end) | |
} | |
) | |
Divider( | |
modifier = Modifier | |
.height(1.dp) | |
.constrainAs(divider) { | |
end.linkTo(parent.end) | |
bottom.linkTo(parent.bottom) | |
}, | |
thickness = 0.5.dp, | |
color = MaterialTheme.colors.secondary, | |
startIndent = 72.dp | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment