Skip to content

Instantly share code, notes, and snippets.

@eevajonnapanula
Created July 11, 2023 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevajonnapanula/c7a3e6721eaa50d295f81c4c532d07a5 to your computer and use it in GitHub Desktop.
Save eevajonnapanula/c7a3e6721eaa50d295f81c4c532d07a5 to your computer and use it in GitHub Desktop.
@Composable
fun RadioInputRow(
text: String,
checked: Boolean,
onChange: (String) -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
// We add a selectable modifier with state and role to the row
.selectable(
selected = checked,
enabled = true,
role = Role.RadioButton,
onClick = { onChange(text) },
)
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = text,
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
RadioButton(
modifier = Modifier.clearAndSetSemantics {},
selected = checked,
onClick = { onChange(text) },
colors = RadioButtonDefaults.colors(
selectedColor = MaterialTheme.colorScheme.tertiary,
unselectedColor = MaterialTheme.colorScheme.tertiary,
),
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment