美文网首页
kotlin - compose 问题记录

kotlin - compose 问题记录

作者: JamesYang1624 | 来源:发表于2021-10-28 14:37 被阅读0次

compose

remember

mutableStateOf

这两个函数的作用是,将本地状态存储在内存中,并跟踪传递给 mutableStateOf 的值的变化。该值更新时,系统会自动重新绘制使用此状态的可组合项(及其子项),通过使用 Compose 的状态 API( remember 和 mutableStateOf),系统会在状态发生任何变化时自动更新界面

 var isExpanded by remember { mutableStateOf(false) }

在使用remember和mutableStateOf函数时,一直提示报错

Type 'TypeVariable(T)' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate

但是导包是正确的:

import androidx.compose.runtime.remember
import androidx.compose.runtime.mutableStateOf

解决办法是:

更换导包

import androidx.compose.runtime.*

就不报错了,然后就能正确的记录列表状态和操作

相关文章

网友评论

      本文标题:kotlin - compose 问题记录

      本文链接:https://www.haomeiwen.com/subject/ajdvaltx.html