Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created April 26, 2024 01:12
Show Gist options
  • Save fvilarino/844c6797d069ac0ae16e962d0b98b357 to your computer and use it in GitHub Desktop.
Save fvilarino/844c6797d069ac0ae16e962d0b98b357 to your computer and use it in GitHub Desktop.
Container Transform - User List
// 1
data class User(
val name: String,
val email: String,
)
// 2
@Composable
fun UserList(
users: List<User>,
modifier: Modifier = Modifier,
) {
// 3
LazyColumn(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(16.dp),
) {
items(
items = users,
key = { user -> user.email },
) { user ->
// 4
UserCard(
user = user,
modifier = Modifier.fillMaxWidth(),
)
}
}
}
// 5
@Composable
fun UserCard(
user: User,
modifier: Modifier = Modifier,
) {
Card(modifier = modifier) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(all = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
LineListItem(label = "Name", value = user.name)
LineListItem(label = "Email", value = user.email)
}
}
}
// 6
@Composable
fun LineListItem(
label: String,
value: String,
modifier: Modifier = Modifier
) {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = modifier,
) {
Text(text = label, style = MaterialTheme.typography.bodyMedium)
Text(text = value, style = MaterialTheme.typography.bodyLarge)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment