Skip to content

Consider Toggleable instead of Card(onClick){Text+Switch} in my Dynamic Color settings #90

Description

@Sottti
Card(
    modifier = Modifier.fillMaxWidth()
) {
    Row(
        modifier = Modifier
            // Makes the entire row the toggle target
            .toggleable(
                value = isChecked,
                onValueChange = { isChecked = it },
                role = Role.Switch
            )
            .padding(16.dp)
    ) {
        Text("Enable Feature", Modifier.weight(1f))
        
        // Switch is visual only; its state is controlled by the Row.
        Switch(
            checked = isChecked,
            onCheckedChange = null // CRUCIAL: Prevents double-toggling
        )
    }
}

instead of

Card(
    onClick = { isChecked = !isChecked } // Handles row click
) {
    Row {
        Text("Enable Feature", Modifier.weight(1f))
        Switch(
            checked = isChecked,
            onCheckedChange = { isChecked = it } // Handles switch click
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions