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
Zach Klippenstein (he/him) [MOD]
06/14/2021, 3:17 AM
Seems fine to me. Another option is to use the scoping functions, eg