stateFlows icon indicating copy to clipboard operation
stateFlows copied to clipboard

How combine use one MutableStateFlow ? and let UI show multi error hint ?

Open CMingTseng opened this issue 3 years ago • 0 comments

Dear Sir

if mix _firstName & _password & _userID at one = MutableStateFlow(UIState)

like

https://github.com/ydhnwb/android-clean-architecture/blob/ab9ab0b69d43489709b0b7954c316366022e4d2a/app/src/main/java/com/ydhnwb/cleanarchitectureexercise/presentation/login/LoginViewModel.kt#L18

https://github.com/Shivamdhuria/stateFlows/blob/master/app/src/main/java/com/example/stateflow/backoff/data/ResultWrapper.kt

i want Validate "input " by combine

like :

    val flowEmail = flowOf(checkEmail(email))
    val flowPwd = flowOf(checkPwd(pwd))

  combine(flowEmail, flowPwd) { r1, r2 ->
            Timber.e("Show result1 $r1  result2 $r2")
            if (r1!=0){
                state.value = UIState.Error("werwerwer")
            }
            if(r2!=0){
                state.value = UIState.Error("ewewrewrewre")
            }
            return@combine (r1 == 0 && r2 == 0)
        } ....
        

when inputs (email & pwd) all error

the state.value has two times change

( the UI is hint "isLegalPassword" & "not email address" )

but UI (XXXFragmnet ) only get one change

how use combine & one MutableStateFlow show detail error ?

THX

CMingTseng avatar Sep 27 '22 11:09 CMingTseng