Diego Marulanda
06/10/2020, 8:12 PM@Composable
fun Residencelist(){
coreApiService.get("${BASE_URL}list/") { response: String ->
val response = Gson().fromJson(response, ResponseResidences::class.java)
MaterialTheme {
Column(Modifier.padding(bottom = 1.dp).fillMaxWidth()) {
VerticalScroller() {
Column(Modifier.padding(3.dp).fillMaxWidth()) {
response.residences!!.forEach {
if (it != null) {
newCarrouselCard(it.name!!,
it.mainImage!!,
it.additionalInformation!!.images,
it.residenceDescription!!,
"${it.price} ${it.currency}")
Divider(height = 10.dp)
} else newCard("Residences not found")
}
}
}
}
}
}
}
and when I try to compile, get this error: Functions which invoke @Composable functions must be marked with the @Composable annotation
in the val
line, but I don't understand why? because I call other normal functions from Glide library and it works,Adam Powell
06/10/2020, 8:15 PMDiego Marulanda
06/10/2020, 8:17 PMAdam Powell
06/10/2020, 8:18 PMsuspend
version of your API service request, (or if you're using retrofit, use the suspend variant it can give you) then use this pattern:
var response by state<ResponseResidences?> { null }
launchInComposition(url) {
response = suspendingGet(url)
}
if (response == null) {
// return, or show a loading state
return
}
MaterialTheme {
// the rest of your UI
Diego Marulanda
06/10/2020, 8:19 PMjw
06/10/2020, 8:19 PMGson
instance for every call which is very bad.Adam Powell
06/10/2020, 8:19 PMlaunchInComposition(...)
then it will cancel and re-launch if the request information changeszhuinden
06/27/2020, 12:10 PM@Composable
function suspending? 🤔Adam Powell
06/27/2020, 2:09 PMCoroutineScope.produce
as hot state updaters