Skip to content

NullPointerException: null cannot be cast to non-null type skip.ui.PreferenceKeyCompanion<Value of skip.ui.Preference> #310

@GavynHolt

Description

@GavynHolt

We have updated Skip packages in a recent release (Skip 1.6.36, Skip UI 1.46.0) and are beginning to see this issue crash some apps on startup.

It seems to be happening surrounding the storage of our colorScheme, which is declared in our main RootView:

public struct RootView : View {    
    @AppStorage(Theme.storageKey) private var theme: String = Theme.SYSTEM.rawValue
    var preferredColorScheme: ColorScheme? {
        switch theme {
        case Theme.DARK.rawValue:
            return .dark
        case Theme.LIGHT.rawValue:
            return .light
        default:
            // nil allows for user's system setting default colour scheme to prevail
            return nil
        }
    }

Digging a bit deeper in our stacktrace shows it may also be coming from Skips templated Main.kt file:

@Composable
internal fun PresentationRootView(context: ComposeContext) {
    val colorScheme = if (isSystemInDarkTheme()) ColorScheme.dark else ColorScheme.light
    PresentationRoot(defaultColorScheme = colorScheme, context = context) { ctx ->
        val contentContext = ctx.content()
        Box(modifier = ctx.modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
            RootView().Compose(context = contentContext)
        }
    }
}

What is confusing me a bit is that we are providing default values for all @AppStorage variables throughout the app.

I did notice this somewhat similar issue, which seems to indicate that preference keys should not be declared private, which we have done.

#243

Is this as simple as now needing to declare @AppStorage vars as the default public? Anything else at play? Thank you. -Gavyn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions