12 questions
0
votes
0
answers
41
views
Flows not updating [closed]
I have two flows: activityState and activityUiState. I need the activityUiState to be of type MutableStateFlow, so I'm using the activityState as a Flow to update the value of the activityUiState. The ...
1
vote
1
answer
47
views
My State Flow wont update the values in the viewmodel
I have this code for image analysis, and I'm trying to pass the processed text data list to the view model. The text is recognized, but it doesn't get properly sent to the view model. I logged the ...
7
votes
5
answers
5k
views
What is better to update a view model's MutableStateFlow, _uiState.update{} or _uiState.value = _uiState.value.copy()?
I am confused what to use, whether to use update or copy for changing/updating the state of UI in Jetpack Compose.
Some say to use
_uiState.update {
it.copy()
}
Some say to use
_uiState.value = ...
1
vote
1
answer
69
views
Initialize MutableStateFlow with database data
Is there a way to initialize a MutableStateFlow with data obtained from a database? I tried the following approach, but the recordedActivityUiState is not updated with the object from the ...
1
vote
1
answer
76
views
MutableStateFlow is not thread safe as doc says in kotlin? [closed]
I have a viewModel, which has a property to indicate where is requesting.
If it's true, then return, otherwise make a new request.
private val _isLoading = MutableStateFlow(false)
val ...
1
vote
1
answer
68
views
android kotlin `when` statement not smart casting
I have the following state sealed interface
sealed interface MainState {
data class Success(
val hasUsername: Boolean = false,
val isSessionActive: Boolean = false) : MainState
...
1
vote
2
answers
250
views
Toast message appears multiple times when navigating back in Jetpack Compose with MutableStateFlow
I'm working on a Jetpack Compose project where I use MutableStateFlow to display a Toast message when saving an article in the DetailScreen. However, when I navigate back to the previous screen using ...
4
votes
2
answers
137
views
Compose screen not recompositioning after state change
I have a ViewModel with a stateFlow. Everytime that a button is clicked, I'm changing the value to the state but, for some reason, the screen is not reacting to that change.
I know that the state's ...
1
vote
1
answer
82
views
Ui does not recompose upon updating the stateflow from the ViewModel
I can change my view model's internal state by calling redirection(verified with Log statements), but it doesn't have any effect on gUiState in my main composable. Why is that?
The main composable ...
0
votes
2
answers
114
views
How can i update UI from service using MutableStateFlow
`When I running my service, UI not update. Service is running because i see update in my log.
This is my simplified example but still it doesn't work.
My service has value MutableStateFlow, every 1 ...
2
votes
2
answers
153
views
Variable not updating from viewModel flow
Can someone tell me why otp value not updated by resetText?
Steps:
type some text in TextField
click "Reset text"
Is it bug or some issues with my code?
ViewModel
@HiltViewModel
class ...
1
vote
2
answers
387
views
Android ViewModel MutableStateFlow Type Mismatch
When working with MutableStateFlow in my viewmodel, I got the following compile error: "Type mismatch. Required: Bar, Found: Unit"
Here is my stripped-down code:
import androidx.lifecycle....