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
1 answer

Kotlin Flows, executing code when there are no active subscribers

I have created a location repository that is responsible for collecting location data and transmitting it to whoever listens, the code right now looks something like this: @Singleton class LocationRepository @Inject constructor( app:…
Cruces
  • 3,029
  • 1
  • 26
  • 55
0
votes
2 answers

MutableStateFlow collector doesn't receive data

I have some view model: private val locationFlow = locationProviderClient.locationFlow(LocationModule.locationRequest) val position = MutableStateFlow(Location(LocationManager.NETWORK_PROVIDER)) val positions =…
Karol Kulbaka
  • 1,136
  • 11
  • 21
0
votes
0 answers

Does a CircularProgressBar stop by default in Kotlin?

I'm getting data from an external API. In the ViewModel class I collect the data as below: private val state: MutableState>> = mutableStateOf(Resource(emptyList())) viewModelScope.launch { repository.getItems().collect {…
0
votes
1 answer

Boolean flows sync

I have few StateFlow fields in the ViewModel class. It's add/edit form screen where each StateFlow is validation property for each editable field on the screen. I would like to write some class FormValidation with StateFlow property for validation…
avvensis
  • 917
  • 10
  • 20
0
votes
1 answer

android Two-way binding cannot resolve a setter for kotlinx.coroutines.flow.MutableStateFlow

Trying to switch an app over to stateflow with databinding but get the error Two-way binding cannot resolve a setter for kotlinx.coroutines.flow.MutableStateFlow xml
android
  • 135
  • 1
  • 6
0
votes
1 answer

Android "Transformations.map()" for MutableStateFlow

For achieving the same functionality of Transformation.map() on StateFlow, I use following code and it works fine: val menuCategoryNames = _menuCategories.mapLatest { menuCategories -> menuCategories.map { "${it.name}"…
Sam Chen
  • 7,597
  • 2
  • 40
  • 73
0
votes
1 answer

Multiple LiveData/StateFlow for one pair of Fragment-ViewModel

I have a Fragment, that represents a screen in a single activity app, and a ViewModel for this fragment. ViewModel uses multiple repositories for loading a set of data from multiple API calls and emit this data to the fragment via multiple…
0
votes
1 answer

What is the appropriate Kotlin Flow to use here while creating an app with compose?

The following is the activity class. class MainActivity : ComponentActivity() { private val viewModel: MainViewModel by viewModels { MainViewModelProvider() } override fun onCreate(savedInstanceState: Bundle?) { …
0
votes
1 answer

How can i handle two way binding in MVI architecture?

I see many articles handling two way binding with MVVM. But i want to handle this issue with single source of truth. I dont want to create multiple stateflows for this case. I have a StateFlow which has all view state inside entity. How can i…
0
votes
1 answer

How do you emit multiple flow values as an object at the repository level?

Say I have two flows: val x: Flow = dao.getValueX() val y: Flow = dao.getValueY() Can I have a third flow, flow z which will emit these two as a pair? Say I have XYObject() where XYObject looks like X: Long? Y: Long? I want to…
0
votes
1 answer

Cannot find a setter for that accepts parameter type 'kotlinx.coroutines.flow.MutableStateFlow' DataBinding Android

I'm using data-binding to handle MutableStateFlow in my ViewModel private val _searchSkeleton = MutableStateFlow(View.GONE) val searchSkeletonVis = _searchSkeleton Here's my usage in the XML file …
A. Albrg
  • 485
  • 4
  • 21
-1
votes
3 answers

How to use delegate property in MutableStateFlow in jetpack compose

I am using MutableStateFlow in my jetpack compose. Like below val isBluetoothEnabled = MutableStateFlow(false) whenever I tried to use the value of variable like this .value i.e. isBluetoothEnabled.value. So I am trying to use delegate property to…
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
-2
votes
1 answer

App crashes when calling a method from viewmodel

I'm trying to make a request to a remote server using retrofit. I'm using clean architecture for separating concerns. From the top level files Retrofit call @GET("/api/dedicated_trips") suspend fun getDedicatedTrips( …
1 2 3
12
13