Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change checked or slider box #6

Closed
Cliftonz opened this issue Sep 24, 2021 · 3 comments
Closed

Unable to change checked or slider box #6

Cliftonz opened this issue Sep 24, 2021 · 3 comments

Comments

@Cliftonz
Copy link

I am unable to change the checked setting on both SettingsSwitch and SettingsCheckbox.

CheckedError

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 Cliftonz changed the title Unable to change checked Unable to change checked or slider box Sep 24, 2021
@Cliftonz
Copy link
Author

I could be using this wrong, please let me know if this is the case.

@Cliftonz
Copy link
Author

I also notice I do not have the touch button in my compose preview of the item.
image

@alorma
Copy link
Owner

alorma commented Sep 25, 2021

You must use:

var darkTheme = remember { mutableStateOf(false) }

@alorma alorma closed this as completed Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants