Questions tagged [kotlin-stateflow]

In Kotlin coroutines, a StateFlow is a mutable value whose changes can be observed as a flow. Use this tag for questions about publishing, transforming and consuming state flows.

A SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors. A state flow is a hot flow because its active instance exists independently of the presence of collectors. Its current value can be retrieved via the value property.

source

194 questions
0
votes
2 answers

Why recomposition doesn't happen when TextFieldValue changes

My ViewModel val names = listOf( "valeria", "Daniela", "Isabella", "Liam", "Noah", "Jack", "Oliver", "Ava", "Sophia", "Amelia" ) private val _namesList =…
0
votes
1 answer

kotlin StateFlow doesn't respond on change in state in some cases

Despite on the state of the StateFlow has been updated StateFlow collect{} is not called. One of the possible reason might be it doesn't pass equality check. So implemented custom equality check to make sure changes in the field I am interested in…
Joe Dow
  • 583
  • 1
  • 3
  • 12
0
votes
1 answer

Coroutine StateFlow.collect{} not firing

I'm seeing some odd behavior. I have a simple StateFlow in my ViewModel that is not being collected in the fragment. Definition: private val _primaryButtonClicked = MutableStateFlow(false) val primaryButtonClicked: StateFlow =…
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
0
votes
2 answers

How to implement pagination with kotlin flows

I am new to kotlin flows. I am following this to set up the UI layer in Android. This is my UI stateFlow private val _teamsUiState = MutableStateFlow(TeamsUiState()) val teamsUiState: StateFlow = _teamsUiState.asStateFlow() This is my…
hushed_voice
  • 3,161
  • 3
  • 34
  • 66
0
votes
1 answer

Rerun StateFlow When Filter Needs to Change?

I have a StateFlow containing a simple list of strings. I want to be able to filter that list of Strings. Whenever the filter gets updated, I want to push out a new update to the StateFlow. class ResultsViewModel( private val api: API ) :…
dave mankoff
  • 17,379
  • 7
  • 50
  • 64
0
votes
1 answer

How to read sealed class subclass in Kotlin?

In my Android studio project, I have a construct like following: @Stable interface Levels { @Immutable sealed class LevelData { object Empty : LevelData() @Immutable data class L1( val locationData:…
Arsene Raul
  • 66
  • 1
  • 9
0
votes
1 answer

Kotlin StateFlow multiple subscriptions after returning from another Fragment

I'm trying to implement StateFlow in my app with MVVM architecture between ViewModel and Fragment. In ViewModel: ... private val _eventDataState = MutableStateFlow(EventDataState.Loading) val eventDataState:…
Vind Iskald
  • 345
  • 3
  • 14
0
votes
2 answers

Updating MutableStateFlow without emitting to collectors

In an Android project, we are currently trying to switch from LiveData to StateFlow in our viewmodels. But for some rare cases, we need to update our state without notifying the collectors about the change. It might sound weird when we think of the…
Ugurcan Yildirim
  • 5,973
  • 3
  • 42
  • 73
0
votes
1 answer

ListAdapter is not being notified whenever data is updated and emitted by StateFlow

StateFlow is emitting new data after change, but ListAdapter is not being updated/notified, but when configuration is changed(i.e device is rotated from Portrait to Landscape mode) update is occurred: class TutorialListFragment : Fragment() { …
Crazy Coder
  • 784
  • 2
  • 9
  • 24
0
votes
1 answer

Kotlin flows junit test freezes when to test collect method

I'm trying to write a component which uses different datasources of data. Then data is combined and emitted in the different resulting flow. class TaskControlComponent( private val diskCacheDataSource: DiskCacheDataSource, private val…
vetalitet
  • 703
  • 2
  • 10
  • 25
0
votes
2 answers

Using StateFlow To Update List Adapter

I am trying to switch from LiveData to StateFlow in populating my ListAdapter. I currently have a MutableLiveData> that I am observing to update the list adapter as such: viewModel.mutableLiveDataList.observe(viewLifecycleOwner,…
0
votes
1 answer

StateFlowImpl collect has a while loop,If I use it on UI Thread,Why it doesn't block UI Thread

If I use while loop on launch,it will keep running,the click event will not execute,eventually lead to ANR. StateFlowImpl collect has a while loop,When will it exit the loop,this is my case: class MainActivity : AppCompatActivity(), CoroutineScope…
summer
  • 11
  • 1
0
votes
1 answer

SharedFlow won't emit value to subscriber at fragment (collect)

I want to use SharedFlow instead of StateFlow because first one doesn't require initial value ViewModel: val photosPaginData = photoRepository.getPhotosPagingData() // Flow> .cachedIn(viewModelScope) …
0
votes
1 answer

filter flowable list of object by category and group into another list of object in flow

is it possible to filter and group Flow> by categories. i found issue quite similar here , but no luck :( here i'm sharing my approach which i tried, code inside viewModel : class HomeViewModel: ViewModel() { data class Car(val id:…
0
votes
0 answers

MutableStateFlow: Cannot invoke setValue on a background thread from Coroutine on ActivityLifecycleCallbacks

Problem I got error message Cannot invoke setValue on a background thread when using MutableStateFlow on ActivityLifecycleCallback, i got this error after updating lifecycle jetpack to 2.4.0 and use repeatOnLifecycle. Calling network interfaces…
1 2 3
12
13