https://kotlinlang.org logo
#orbit-mvi
Title
# orbit-mvi
e

Eric Ampire [MOD]

09/04/2021, 8:54 PM
Hello everyone, Is there a problem with this code that can cause the state not to be modified? The logs display very well when there is an error or when the operation is successful but at the view level the state has always the default value
Copy code
private fun Flow<Result<List<Lottiefile>>>.fetchData() = intent(registerIdling = false) {
    collect { result ->
      when(result) {
        is Result.Error -> {
          Timber.e(result.toString())
          val errorMessage = result.exception.localizedMessage ?: "Unknown Error"
          reduce { state.copy(isLoading = false) }
          postSideEffect(ExploreEffect.ShowErrorMessage(errorMessage))
        }
        Result.Loading -> {
          Timber.e(result.toString())
          reduce { state.copy(isLoading = true) }
        }
        is Result.Success -> {
          Timber.e(result.toString())
          reduce { state.copy(files = result.data, isLoading = false) }
        }
      }
    }
  }
The state is collected like that
Copy code
val state by viewModel.container.stateFlow.collectAsState()
m

Mikolaj Leszczynski

09/06/2021, 6:26 AM
@Eric Ampire [MOD] I have a hunch - how are you overriding the
container
field?
o

Oleksii Malovanyi

09/06/2021, 7:11 AM
also, I’ve found kotlin still doesn’t play nice with
Flow<Result>
-> try removing the Result from the type
e

Eric Ampire [MOD]

09/06/2021, 7:20 PM
Here the code @Mikolaj Leszczynski
o

Oleksii Malovanyi

09/06/2021, 7:30 PM
@Eric Ampire [MOD] the container you use for state is not the same instance of container used for
intent{}
-> remove get() in favour of property initializer
☝️ 1
e

Eric Ampire [MOD]

09/06/2021, 10:03 PM
Okay thanks, it's working
12 Views