Is binding the current value of a piece of state t...
# compose
d
Is binding the current value of a piece of state to a local variable so that the compiler can infer it isn't null a valid pattern, or is there a better way to do this?
Copy code
val trackSettingsState = repo.trackSettings().collectAsState(initialValue = null)
val trackSettings = trackSettingsState.value

if (trackSettings == null) {
   Spinner()
}

TextField(trackSettings.frequency, /* ... */)
Text(trackSettings.name)
I could also use a with statement or an else branch, but I prefer handling the null-case up front and then being able to assume it isn't null later
z
Seems fine to me. Another option is to use the scoping functions, eg
let
👍 1