Questions tagged [kotlin-flow]

In Kotlin coroutines, a Flow is a stream of asynchronously computed values. Use this tag when you're having problems building, transforming or consuming flows.

In Kotlin coroutines, a Flow is stream of asynchronously computed values.

Documentation: https://kotlinlang.org/docs/flow.html#flows

895 questions
0
votes
2 answers

How to propagate the response of an async operation to the view using Jetpack Compose?

I have this sealed class: sealed class Resource { object Loading: Resource() data class Success(val data: T): Resource() data class Failure(val message: String): Resource() } In the repository class I…
0
votes
2 answers

how to return an object in a suspended function after receiving the object from a Flow?

I'm wondering if there's a way to wait for a flow to be complete and return the result inside a suspend function. transactionRepository.getAll(accountId) returns a flow of transactions override suspend fun getAccount(accountId: Int): Account { …
DennisVA
  • 2,068
  • 1
  • 25
  • 35
0
votes
1 answer

What is the correct way of handling collect in Kotlin?

I'm getting user data from Firestore using MVVM. In the repository class I use: fun getUserData() = flow { auth.currentUser?.apply { val user = ref.document(uid).get().await().toObject(User::class.java) user?.let { …
0
votes
1 answer

How to manually map a Room one-to-one relationship using Kotlin Flow

In my scenario there is a one-to-one relationship between transactions and categories. In order to query the list of transactions and corresponding categories, documentation tells me i must first model the one-to-one relationship between the two…
DennisVA
  • 2,068
  • 1
  • 25
  • 35
0
votes
1 answer

Kotlin Flow, callback

I have created the following extension function : fun Flow.handleErrors(showError: Boolean = false, retry: Boolean = false, navigateBack: Boolean = true): Flow = catch { throwable -> var message:…
George
  • 2,865
  • 6
  • 35
  • 59
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
2 answers

LiveData Observer triggers when not needed

I have a viewmodel that receives flow as livedata from scenario val state get () = syncScenario.state.asLiveData () In the activity, we subscribe to this livedata, some logic happens and used the activityResult private val resultLauncher =…
Qrampus
  • 39
  • 4
0
votes
1 answer

stateIn operator doesn't update the cached value of StateFlow

I have some shared flows which are merged into several flows in different classes and then these flows are merged into a single one. The original shared flows are configured as such: protected val statusMutable = MutableSharedFlow() val status:…
solru
  • 111
  • 1
  • 8
0
votes
1 answer

How add dynamic values in Kotlin Flow

if we know list values to be processed in Kotlin flow then we can follow the below function flow { (1..1000).forEach { delay(1000) //Process Data emit(it.toLong()) } }.collect{ …
Mohan K
  • 464
  • 5
  • 18
0
votes
1 answer

Write extension function on Flow.catch

I would like to modify the default Flow.catch function and always call a specific suspend function logOutIfUserHasNoAccount(). My current implementation is: private suspend fun Flow.catchLoginError(action: suspend FlowCollector.(Throwable)…
Andrew
  • 4,264
  • 1
  • 21
  • 65
0
votes
0 answers

Flow with Room in Kotlin

i am new to kotlin android i am trying to use room with flow my code as follows my entity as follows @Entity(tableName = "user_data") data class User ( @PrimaryKey(autoGenerate = true) val id:Int, val firstName:String, val…
0
votes
1 answer

Cannot Emit Either.Left in Flow because of type mismatch

Here I have i function that gets some data. I use Either for sending data to ViewModel. sealed class Either { /** * Represents the left side of [Either] class which by convention is a "Failure". */ data class Left(val a:…
Grigoriym
  • 328
  • 3
  • 7
0
votes
1 answer

Kotlin Flow - Android: Application gets stuck in flow combine and does not move ahead

I am trying to combine two flows and then send the value to a function and then collect the result. My code never goes to second line of combine and never comes to collect results block. What am I missing can anyone pls explain. Below is my…
keshav kowshik
  • 2,354
  • 4
  • 22
  • 45
0
votes
0 answers

Kotlin coroutines channel mapLatest confusion

My aim is to have a long lived singleton (that survives fragments being destroyed and that will be used by various view models in my app). This singleton will expose a Channel, which I want to send values to. This singleton will be…
Thomas Cook
  • 4,371
  • 2
  • 25
  • 42
0
votes
1 answer

Android Observable Queries not working after adding suspend word

I am trying to migrate from LiveData to Kotlin Flow. Right now I am working on a project that has offline supports in Room. I was looking through the documentation and I managed to write an observable query in coroutines with Flow. (see: here) The…
Marian Pavel
  • 2,726
  • 8
  • 29
  • 65