Has anyone implemented a Kotlin solution to creating non-nullable LiveData types? Trying to think of the best way to do this.. Right now I have an extension function which will get the value only if it's not null, otherwise throw (as the value should never be null), but I'd much rather do it as a functionality of the setter and force the LiveData to have an initialization value as well as not being able to set it to null.
Shan
09/26/2019, 7:57 PM
1. LiveData has a constructor in its class which will initialize the class with no value passed, which I would like to do away with (without making my own observable.. if anyone has any suggestions)
2. LiveData annotates its
getValue
function with
@Nullable
which I would also like to do away with.
l
louiscad
09/26/2019, 8:07 PM
My solution is to use
Flow
and bridge it to
LiveData
, not exposing
MutableLiveData
, and I observe only notNull values, with an extension (that I can link if you want)
➕ 1
s
Shan
09/26/2019, 8:07 PM
Please do! That sounds very promising
Shan
09/26/2019, 8:08 PM
I intend to replace my LiveDatas with Data Flows when they are released at some point, hopefully soon!