All Questions
Tagged with android-jetpack-compose kotlin-flow
128
questions
1
vote
1
answer
26
views
How can I retrieve the value from my roomDatabase before the Text composable needs it so it doesn't display null?
In my app, a Text composable calls the roomViewModel to display the energyState, but it shows null. I want the observer (the Text composable), to display the value of the "energy" column ...
1
vote
1
answer
42
views
collectAsStateWithLifecycle() collects SharedFlow only after clicking a button
I found that SharedFlow is collected correctly by collectAsStateWithLifecycle() only when I click a button instead of waiting to timeout or when I change replay to 1. In other cases it is collected ...
0
votes
0
answers
64
views
How to update uiState in ViewModel when an event occurs?
I'm just learning how to manage UI States. In the following example I'm using combine() for 2 of my use cases and they are collected when the app starts. But what if I want to collect a 3rd different ...
0
votes
1
answer
66
views
Navigate to next screen when the api call is finished
I want to go to another screen only when the api call is finished. I'm using the below code and it works fine in splash screen (i can see the api call happening in log cat) but when i navigate and try ...
0
votes
1
answer
69
views
How to query a Room db from a composable to get item details
Having an application with Room and Compose, I'm on a composable that needs to retrieve data from the database for painting it. It is a list of favorite flights, and favorite only haves the IDs (iata) ...
0
votes
1
answer
60
views
How to init TextField with datastore variable
Having a composable which has a textfield which needs to work with a by remember mutablestateof String called text, that variable must be initialized with a datastore stored value. I have the ...
1
vote
1
answer
20
views
Loading state controlled with MutableStateFlow does not update the UI
I have a view model injected with hilt that controls the state of a loading spinner, which is a fullscreen dialog.
@HiltViewModel
class MyViewModel @Inject constructor(
val coordinator: ...
1
vote
2
answers
60
views
Switching from .first() to .collect{} on a Flow stopped data appearing on screen
I did a viewmodel with Flow and Room that connected my variables on the UiState with Room using .first() as the codelabs showed me. I noticed that using .first() is not a good idea because when I ...
0
votes
1
answer
139
views
Observe BroadcastReceiver in view model using flows
I know this type questions have already been asked here but none of them worked for me so I'll ask here.
I'm developing a VPN app using kotlin and jetpack compose. The core of our app uses this custom ...
0
votes
2
answers
56
views
Kotlin Flows not working as expected when Collecting items in UI Screen using collectAsState(). Also maybe taskDao.insertTask() not working?
`The Task data is not being inserted in database, therefore not collected and rendered in UI.
#TaskViewModel.kt
var taskList: StateFlow<List<Task>> = repository.getAllTasks()
....
1
vote
0
answers
28
views
Kotlin LazyPagingItems and itemCount parameter init value to 0
I'm faced with what I consider a bug on LazyPagingItems for a few days and, now that I've found a workaround, I've been thinking about this and if there's an efficient method to solve the issue.
For ...
0
votes
4
answers
899
views
In compose collectAsStateWithLifecycle is not working
Problem:
I have used collectAsStateWithLifecycle to collect the flow
Now once I initiate the flow and minimize the app still the flow is active
According to collectAsStateWithLifecycle flow emission ...
0
votes
0
answers
27
views
Problem with Using Flows in ViewModel instances
In a list of posts each post has a like button, which calls a db transaction. But db transactions and gui works accurately if either the list consists of only one post or for the last post in the list
...
0
votes
1
answer
72
views
How to update a flow on interval when app is in foreground and not when in background
I have a flow in a view model which emits the user's location every 15 seconds
val locations = MutableStateFlow<List<StoreLocation>>(emptyList())
private val _locations = ...
0
votes
1
answer
632
views
Kotlin compose, when doing collectAsState on a StateFlow how to perform an action after collection finishes
So lets imagine I'm collecting a state flow using collectAsState in my composable:
@Composable
internal fun Test(
myViewModel: MyViewModel = viewModel()
) {
val state by myViewModel....