the .collect part of the import stays red. I have checked for typos, checked my jetpack compose version and I have invalidated my cache and restarted android studio, but the error didn’t disappear. How can I solve this issue?
I am using collect in this function:
import androidx.compose.runtime.collect
fun startLocationUpdates() {
locationUpdateScope.launch {
location.collect { locationData: LocationData -> // Collect changes in location state
if (locationData != null) {
user.longitude = locationData.longitude
user.latitude = locationData.latitude
networkManager.UpdateLocation(user)
delay(timeMillis = 5000L) // Delay between updates// Pass location to updateLocation
}
}
}
}
2
Answers
Is your build.gradle file set up with the dependencies? https://developer.android.com/jetpack/androidx/releases/compose-runtime#declaring_dependencies
e.g.
then clean and rebuild your project
Build -> Clean Project
Build -> Rebuild Project
If these steps worked, can you mark this answer as accepted
I’m not aware there exists a function
androidx.compose.runtime.collect
.If
location
is aFlow
you can use this instead:If
location
is a ComposeState
then you shouldn’t try to observe it directly. Just use it in a@Composable
function and let the compose runtime manage that automatically.