Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Perfect. Is there any way to change the secondaryLabel depending on the checked state?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o3-mini’s answer.
  1. User

    Perfect. Is there any way to change the secondaryLabel depending on the checked state?

  2. Claude Assistant

    Yes! You can conditionally change the secondaryLabel based on the checked state. Here's how:

    ToggleChip(
        modifier = Modifier.fillMaxWidth(),
        label = {
            Text("Brightness Mode")
        },
        secondaryLabel = {
            Text(if (autoBrightness) "Automatic" else "Manual")
        },
        onCheckedChange = { isChecked ->
            val newMode = if (isChecked) {
                Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
            } else {
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
            }
            
            Settings.System.putInt(
                contentResolver, 
                Settings.System.SCREEN_BRIGHTNESS_MODE, 
                newMode
            )
            autoBrightness = isChecked
        },
        checked = autoBrightness,
        toggleControl = { 
            Switch(checked = autoBrightness)
        },
    )
    

    The key change is in the secondaryLabel:

    secondaryLabel = {
        Text(if (autoBrightness) "Automatic" else "Manual")
    }
    

    Since autoBrightness is now a Compose state variable, any change to it will trigger a recomposition and update the secondary label text accordingly. When the toggle is on, it will show "Automatic", and when it's off, it will show "Manual".

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

Identical first prompt