compose
remember
mutableStateOf
這兩個(gè)函數(shù)的作用是冠摄,將本地狀態(tài)存儲(chǔ)在內(nèi)存中梗摇,并跟蹤傳遞給 mutableStateOf 的值的變化拓哟。該值更新時(shí),系統(tǒng)會(huì)自動(dòng)重新繪制使用此狀態(tài)的可組合項(xiàng)(及其子項(xiàng))伶授,通過使用 Compose 的狀態(tài) API( remember 和 mutableStateOf)断序,系統(tǒng)會(huì)在狀態(tài)發(fā)生任何變化時(shí)自動(dòng)更新界面
var isExpanded by remember { mutableStateOf(false) }
在使用remember和mutableStateOf函數(shù)時(shí),一直提示報(bào)錯(cuò)
Type 'TypeVariable(T)' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate
但是導(dǎo)包是正確的:
import androidx.compose.runtime.remember
import androidx.compose.runtime.mutableStateOf
解決辦法是:
更換導(dǎo)包
import androidx.compose.runtime.*
就不報(bào)錯(cuò)了糜烹,然后就能正確的記錄列表狀態(tài)和操作