Unable to change checked or slider box
Closed this issue · 3 comments
Cliftonz commented
I am unable to change the checked setting on both SettingsSwitch and SettingsCheckbox.
Gradle Settings
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.CliftonSoftware.hobbsLogger"
minSdk 29
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
Here is the code I am using:
@Composable
fun SettingScreenContent(
){
var darkTheme = remember {false}
var icon = remember{Icons.Default.ModeNight}
Column() {
SettingsSwitch(
icon = {
Icon(imageVector = icon , contentDescription = "Theme")
},
title = { Text(text = "Dark Theme") },
checked = darkTheme,
onCheckedChange = {
icon = if(icon == Icons.Default.ModeNight){
Icons.Default.LightMode
}else{
Icons.Default.ModeNight
}
darkTheme = !darkTheme
},
)
}
}
Cliftonz commented
I could be using this wrong, please let me know if this is the case.
Cliftonz commented
alorma commented
You must use:
var darkTheme = remember { mutableStateOf(false) }