Hello, I have a problem with `isSystemInDarkTheme(...
# compose
j
Hello, I have a problem with
isSystemInDarkTheme()
I am adding it to the theme but sometimes it returns true after false
Copy code
2022-08-10 17:12:22.215 6489-6489/ E/isSystemInDarkTheme: true darkMode 
2022-08-10 17:12:23.338 6489-6489/ E/isSystemInDarkTheme: true darkMode 
2022-08-10 17:12:24.478 6489-6489/ E/isSystemInDarkTheme: false darkMode 
2022-08-10 17:12:30.008 6489-6489/ E/isSystemInDarkTheme: false darkMode 
2022-08-10 17:12:30.697 6489-6489/ E/isSystemInDarkTheme: false darkMode
Copy code
@Composable
fun Theme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    ProvideHapiColors(colors) {
        MaterialTheme(
            colors = if (darkTheme) darkColors() else lightColors(),
            typography = Typography,
            shapes = Shapes,
            content = content
        )
    }
}
c
Do you notice the theme changing as well?
j
yes sir
sometimes dark is shown and other times light
use compose 1.2.0-beta02
c
Do you have a snippet of where you are using this Theme?
j
yes, one moment
Copy code
setContent {
    Theme {
        Surface(
            color = HapiTheme.colors.uiBackground,
            modifier = Modifier.fillMaxSize()
        ) {
            App(
                activity = this@MainActivity,
                application = application
            )
        }
    }
}
c
And do you have the code for HapiTheme?
And are you seeing the theme changes on Preview or on device?
j
Copy code
@Composable
fun HapiTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colors = if (darkTheme) {
        DarkColorPalette
    } else {
        LightColorPalette
    }

    ProvideHapiColors(colors) {
        MaterialTheme(
            colors = if (darkTheme) darkColors() else lightColors(),
            typography = Typography,
            shapes = Shapes,
            content = content
        )
    }
}
if it is a device
168 Views