v79
04/09/2021, 8:30 PMvar something = remember { mutableStateOf<MyClass>(_* can't construct here because it's currently null *_) }
?Eric Chee
04/09/2021, 8:36 PMBig Chungus
04/09/2021, 8:36 PMv79
04/09/2021, 8:38 PMv79
04/09/2021, 8:39 PMv79
04/09/2021, 8:40 PMEric Chee
04/09/2021, 8:45 PMsealed class State {
object Loading: State()
class Ready(val myClass: MyClass): State()
}
// your code
val nullableFoo = ...
var state = remember { mutableStateOf<State>(
if (nullableFoo != null) Ready(MyClass(nullableFoo)) else Loading
)}
when (state) {
is Loading -> // show loading component
is Ready -> state.myClass.... // show some component with state.myClass
}
Eric Chee
04/09/2021, 8:51 PMsealed class Result<out T : Any> {
data class Success<out T : Any>(val data: T) : Result<T>()
data class Error(val exception: Exception) : Result<Nothing>()
}
Big Chungus
04/09/2021, 8:56 PMv79
04/09/2021, 8:56 PMBig Chungus
04/09/2021, 8:57 PMBig Chungus
04/09/2021, 8:58 PMv79
04/09/2021, 8:58 PMmutableStateOf<FontModel?>(null)
v79
04/09/2021, 8:59 PMFont
classes (and a Compose function called Font
).