288 questions
1
vote
1
answer
54
views
Change MutableStateFlow after dependent parameter initialization
Developing app using Room and Compose. I want to achieve the following:
User opens Screen A with list of parent categories.
User opens Screen B by clicking category: during the navigation, app passes ...
2
votes
1
answer
95
views
Composable isn't updating when I change input to the Room using StateFlow and collectAsStateWithLifecycle [closed]
My UI is not updating to show the new list of items when I change customers.
I have a Composable screen to display the customer and a list of the items for that customer. When I select a new customer, ...
4
votes
1
answer
124
views
State flow doesn't emit new value when sorting a Map
I’m using Jetpack Compose with StateFlow in a ViewModel. I have a Map<String, List<Int>> and I want to sort it by the size of each list, then display the sorted result in the UI.
Inside my ...
0
votes
1
answer
72
views
Separate instance of classes calling Composable function
Let's say I have some kind of structure like this:
data class C(val value: Int) {
@Composable
fun MyComposable() {
Text("Value: $value")
}
}
@Composable
fun ...
1
vote
1
answer
111
views
UI State Not Updating Properly After Fetching Data in Jetpack Compose
I'm working on a Jetpack Compose app where I fetch book data from a server using a BooksViewModel. The UI should update based on the state (Loading, Success, or Error). However, the UI only shows the ...
5
votes
1
answer
235
views
Why is initialValue needed in collectAsStateWithLifecycle for StateFlow?
I have a ViewModel that exposes a StateFlow representing the UI state of a book list:
class BooksViewModel(private val getBooksUseCase: GetBooksUseCase) : ViewModel() {
val booksState: Flow<...
2
votes
2
answers
228
views
How to correctly display a list from a view model StateFlow in a composable?
I have created a compose project that follows the standard architecture sttucture of a project. It has a data class, interface, api class, repository. The repository is connected to a viewmodel and ...
5
votes
1
answer
155
views
Is ShareIn working as suppossed in Kotlin?
I have a repository function that returns me the user profile:
private val repoScope = MainScope()
fun getProfile(): CommonFlow<User> =
firestore.collection("User")....
0
votes
0
answers
116
views
How to retain dialog visibility after navigating back in Jetpack Compose with NavHostController?
I am using Jetpack Compose with a NavHost and NavHostController to handle navigation. I have a dialog that appears when a button is clicked. This dialog includes a button that navigates to another ...
1
vote
2
answers
111
views
How to update a value of a UiState on a StateFlow?
Having this on my viewmodel:
val uiState: StateFlow<BusStopsDBScreenUiState> = busDataRepository.getBusStops()
.map<List<BusStop>, BusStopsDBScreenUiState> { busStops ->
...
1
vote
1
answer
139
views
Kotlin - why does my test on StateFlow return "stops by timeout"?
I am trying to better understand how StateFlow can be used by writing simple code in a scratch file in Android Studio.
I just want to update a StateFlow and collect the result. The code is the ...
0
votes
1
answer
634
views
How to use Flow in iOS from my kotlin repository?
In my KMM app, I have my kotlin shared code with this method:
fun getUserProfile(): Flow<UserInfo?> =
firestore.collection("UserInfo").document(auth.currentUser!!.uid)....
1
vote
1
answer
42
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 ...
1
vote
1
answer
99
views
How to change the value of a repository Flow?
I came across this article:
https://proandroiddev.com/loading-initial-data-in-launchedeffect-vs-viewmodel-f1747c20ce62
In this article, the author, while describing the advantages and disadvantages of ...
0
votes
2
answers
83
views
MutableStateFlow emission criteria explanation
I'm writing a simple todo app using compose and stateflow.
data class Task(
val name: String,
val isCompleted: Boolean,
val date: Long
)
class SomeViewModel : ViewModel() {
private ...
1
vote
1
answer
80
views
Collecting a flow does not produce any update
In a sample project I have a viewModel with two use cases. Both use cases call the same repository. One fetches via a flow a list of tasks that stores the repository in a StateFlow. The other provides ...
1
vote
1
answer
49
views
uiState doesn't update as expected
Whenever I trigger the "FavoritePost" or "DeletePost" and the uiState has TAB_TWO (Favorites) selected it either swaps to TAB_ONE, stays in TAB_TWO but displays all the Posts ...
3
votes
2
answers
122
views
View not updating after update to viewModel
I have the below list of items which has a checkbox next to each item in the form of a button. When the button is not selected, a black empty circle should show. When the button is selected there ...
4
votes
2
answers
134
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
165
views
How do I manage uiState for multiple sections?
I'm currently developing an Android app that displays multiple sections of movie lists. Each section's UI state is managed independently using separate StateFlows in the ViewModel. Here's a simplified ...
0
votes
1
answer
209
views
collect flow doesn't receive value from repository/usecase in viewmodel - android coroutines
I have a Repository + UseСase + ViewModel + MVI architecture.
I have a UseCase for collecting Flow, and another UseCase to update Flow in repository When I go to the screen, collect fires and gives me ...
1
vote
1
answer
51
views
Nullable StateFlow not updating Compose UI
I know this have been asked many times, but none of the solutions helped me.
I have a StateFlow<String?> that is supposed to guard a token when it arrives from an API call.
it is implemented in ...
2
votes
2
answers
189
views
How do I update the collection correctly to update StateFlow?
In my application, when updating the map StateFlow is not updated. Help me update StateFlow correctly.
data class PageData(val selectedCheckbox: Int, val enable: Boolean)
@HiltViewModel
internal ...
2
votes
2
answers
449
views
Flow not observing changes in a variable
I need that when the var called CustomSingleton.customVar stored in a singleton is modified, my composable gets recomposed to change the current screen in the navhost. So I did this on the viewmodel ...
1
vote
1
answer
91
views
How to stop the screen flicker/refresh for LazyVerticalgrid with pagination?
When the first page results (20) are scrolled down and when there are new results from the next page the screen flickers/refreshes. Tried many things but no idea how to stop this screen flickering.
...
1
vote
1
answer
155
views
Best way to use ArrayList in in Kotlin/MVVM. StateFlow vs Flow vs suspend
I am trying to upgrade my java code to kotlin but I don't know how to aproach this transition. It seems that I have to perfectly understand corutines which is a pain because it seems too much all at ...
1
vote
1
answer
105
views
get data from room and IllegalArgumentException: Key "968031" was already used
In my application I get the list of films by api and can add them to the list of favourites which is stored in the database room. So on the screen with the list of favourite films when I try to delete ...
2
votes
1
answer
92
views
How to use material 3 (1.2.1) and asFlow?
I made some changes to Skizo-ozᴉʞS ツ variant and now it works fine:
private val eventsChannel = MutableSharedFlow<Event>(
replay = 1, extraBufferCapacity = 64,
onBufferOverflow = ...
1
vote
1
answer
264
views
Flow doesn't emit in test when using Dispatchers.Main.immediate (or viewModelScope) to change the value of a StateFlow
I investigated for hours and searched the web (and even bothered ChatGPT) and I'm puzzled this hasn't been solved yet to my (obviously very limited) knowledge.
So this is the setup: I have a view ...
1
vote
1
answer
484
views
Android Kotlin/Compose ViewModel - two SateFlows for two separate fucntions to one StateFlow for UI ViewModel?
Firstly, I'm not a developer or anything, but I wanted an app that doesn't exist for my phone and I understand a minimal amount of coding, went through the Android Kotlin/Jetpack Compose basics course,...
1
vote
1
answer
43
views
Can't access MutableStateFlow value in activity
I Have the following sealed class
sealed class SearchedState {
data class FoundCrag(val crag: Crag): SearchedState()
data class FoundZone(val zone: Zone) : SearchedState()
data class ...
1
vote
2
answers
378
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....
0
votes
0
answers
89
views
Flow subscribe/collect on Android is catch in 2 fragments
I am building an app and I am using Flow and State.
I have 2 fragments A and B. They are never displayed at the same time.
In each fragment I am observing the change of state as below:
private fun ...
1
vote
1
answer
1k
views
How to update elements inside a MutableStateFlow and dynamically change the UI?
I'm relatively new to Android development. While designing the application, I encountered some problems. Everything I found did not quite cover my needs. I would like to listen to your pieces of ...
1
vote
1
answer
1k
views
MutableMap State value not updated on the UI (Kotlin Jetpack Compose)
I'm using a MutableMap to save the data which is updates every 5 seconds and I expect also to be updated the UI showing part of the Map.
After trying different solution I found that if I add another ...
0
votes
0
answers
395
views
Why does my Jetpack Compose screen recompose every time I click on a button?
I'm currently working on a Jetpack Compose screen in my Android app, and I've noticed that every time I click on a button, the entire screen seems to recompose. This behavior is causing some ...
2
votes
1
answer
368
views
Android Jetpack Compose Room query depending on Flow
I'm trying to achieve the following behavior on my TODO app:
when user touches a circle in the top bar a date is selected and the tasks list must change to show tasks of that date
when user touches a ...
4
votes
1
answer
593
views
Unit Test a StateFlow from SnapshotFlow only emits initialValue
I have LoginViewModel which contains Compose state backed field for email and password. I want to create a StateFlow for enabling/disabling the Login button. I use combine and snapshotFlow, and ...
1
vote
1
answer
215
views
Can StateFlow have multiple collectors? Unable to understand the difference between StateFlow and SharedFlow
Created below MutableStateFlow for understanding how collecting works using StateFlow. Is the below code valid? How we can right correctly?
val _mutableStateFlow = MutableStateFlow(0)
val stateFlow: ...
1
vote
1
answer
1k
views
combining multiple mutablestates
just started picking up Compose MP and have been running into difficulty combining 2 sources of mutablestates to a new mutablestate or flow within a viewmodel.
per documentation,
I figured ...
2
votes
2
answers
895
views
Unit Testing StateFlow Created By StateIn
I have a viewmodel class that uses a StateFlow that is created using the StateIn operator.
I.E.
private val _state = MutableStateFlow(MyState())
private val myItems = myRepository.myFlow.stateIn(
...
1
vote
1
answer
53
views
Display dynamic list of items which are not saved in local room database
I have two StateFlows of lists in ViewModel (local and remote), which are combined into single uiState, which is used in Compose user interface.
User is picking values from remote source which are ...
1
vote
3
answers
289
views
Kotlin Stateflow new value emitted but not collected
I have a fragment that shows a location after collecting it from the viewmodel stateflow, the location is stored in shared preferences than emitted to a mutableflowstate when the fragment starts.
The ...
0
votes
1
answer
32
views
StateFlow.collect callback not firing when my adapter changes
I have this fragment that has a recycler view with it's adapter, and I have this methods
private fun observeItemsStateAndSetButtonStyle(type: String) {
when(type) {
TaxonomyType.PROVINCE....
4
votes
3
answers
5k
views
Kotlin Coroutines StateFlow not emitting identical values consecutively—How to force collection or work around this behavior?
I'm encountering a situation where a MutableStateFlow in my Kotlin code isn't emitting the same value twice in a row, even when I explicitly call emit() with the same value. This is preventing my ...
1
vote
0
answers
80
views
Idea needed: How to make viewmodel state - drag&drop in compose list that can be edited
I have a very simple list on the screen. Data goes from viewmodel state from database as observable flow (very ordinary case)
List item is very simple: it has id, name, order_ (the order of item in ...
1
vote
0
answers
152
views
Flow is not collected from room after an update
I am currently migrating an android application from XML, Databinding and Flow/LiveData to Compose, Flow/StateFlow.
In this application, I have a very simple Room database:
@Entity
data class User(@...
0
votes
1
answer
173
views
How to create MutableStateFlow of Webview in ViewModel class in android
How can I manage webview state flow in ViewModel class.
Something like:
private val _webView = MutableStateFlow(WebView())
val webView: StateFlow<WebView> get() = _webView
fun getWebViewHtml(){
...
1
vote
0
answers
49
views
How to test to get all value of StateFlow in Coroutine?
Test Result is always received first value(=init) and last value(=success)
How to get LoaderType State (Fail Case)
Without the delay() function, the test case consistently fails, and only the initial ...
0
votes
1
answer
286
views
StateFlow Doesn't Emit on Field Changes
I have a data class:
data class Student(
val name: String,
var isSelected: Boolean = false
)
And in the ViewModel:
class FirstViewModel : ViewModel() {
private val _student = ...